Finishing face questions (a)

1, if you come into contact with the reflection mechanism in the OC? Simple talk about the concept and use

     A: First, class reflection 

            1, the class name string instance object Class class NSClassFromString @ (@ "student"); Student * stu = [[class alloc] init];

            2, the character string becomes the name of the class Class class = [Student class]; NSString * className = NSStringFromClass (class);

           Two, SEL reflection

            1, by the method of Example string method SEL selector = NSSelectorFromClass (@ "setName"); [stu performSelector: selector withObject: @ "Mike"];

            2, the method of the string into NSStringFomrSelector (@ selector * (setName :))

2, class methods and instance methods what is the difference and contact?

      A: The class methods can only be invoked through the class object, class methods in other classes can call the methods, class methods can not access the member variables, class methods can not directly call the object methods;

            Examples of methods can only be invoked by instance object, a method can call instance methods directly, you can access the member variables, instance methods also can call the class method (by class name)

 

Guess you like

Origin www.cnblogs.com/xiaonizicome/p/10975265.html