Case
-When we use the navigation bar controller Uinavgationcontroller, and when using the System return button, the system will also have a uiscreenedgepangesturerecognizer gesture, And often sometimes we customize a nice back button, and then we need to customize a button and add a gesture. It's easy, isn't it? Yes, but what should you do with the target and @selector of your gestures with Apple? That's what we're going to do today.
Steps
1. By printing, we can see the value of the Action,target, but how to remove the target?
-KVC: Prerequisite: Must know property name
-Run time
2. To use the runtime, you must first import a header file objc/runtime.h
#import <objc/runtime.h>
3. Get the property name using runtime
-Traverse all properties within a class Ivar: Represents member properties
-Copyivarlist can only get the property under which class, and does not go out of bounds (the property of its parent class is not traversed)
-Class gets the member properties of which classes
-Count: Tells you the total number of member properties within the current class
UnsignedintCount =0; //returns an array of member propertiesIvar *ivars = Class_copyivarlist ([uigesturerecognizerclass], &count); for(inti =0; I < count; i++) { //Remove member VariableIvar Ivar =Ivars[i]; //Get Property nameNSString *ivarname =@ (Ivar_getname (Ivar)); NSLog (@"%@", Ivarname); }
4. Print each member property, you can see _targets this looks like a property, next we to verify.
5. Get the value of this key, by printing the discovery system rewrite the descriptions property, we do not get the desired properties, however, there is no egg, we can get through the breakpoint.
Gets the value of this property
Nsarray *targets = [Self.interactivepopgesturerecognizer valueforkeypath:@ "_targets" ];
ID OBJC = [targets firstobject]; NSLog (@ "%@", OBJC); ID target = [OBJC Valueforkeypath:@ "_target"];
-It's not what we want.
-OK, that's what we want, to successfully get _target this property
-print target, that's what we want.
Conclusion: All properties under the current class can be removed by the runtime. I'm going to talk about it today, and next time I'll write about how to do the dictionary-to-model through the runtime, because sometimes our dictionary key is sometimes a keyword, so we may not be able to define it directly as a property, as detailed below.
Use runtime to get Apple private properties