IOS-OC-Basic-NSObject common method, ios-oc -- nsobject
1 Person * person1 = [[Person alloc] init]; 2 Person * person2 = [[Person alloc] init]; 3 4 // you can call private methods in the class, however, there will be a warning 5 [person1 extends mselector: @ selector (actionTow)]; 6 [person1 extends mselector: @ selector (actionOne :) withObject: @ "test"]; 7 8 NSLog (@ "person1 address: % p", person1); 9 NSLog (@ "person2 address: % p", person2 ); 10 11 // compare whether the addresses of two objects are the same 12 if ([person1 isEqual: person2]) {13 NSLog (@ "the addresses of the two objects are the same "); 14} else {15 NSLog (@ "Two object addresses are different "); 16} 17 18 // determine whether an object belongs to a class or its parent class 19 if ([person1 isKindOfClass: [Person class]) {20 NSLog (@ "person1 belongs to the Person class"); 21} 22 23 if ([person1 isKindOfClass: [NSObject class]) {24 NSLog (@ "person1 belongs to NSObject class"); 25} 26 27 28 // determines whether an object belongs to a class, but cannot determine its parent class 29 if ([person1 isMemberOfClass: [Person class]) {30 NSLog (@ "person1 belongs to Person class "); 31} else {32 NSLog (@ "person1 is not in the Person class"); 33} 34 35 if ([person1 isMemberOfClass: [NSObject class]) {36 NSLog (@ "person1 belongs to NSObject class"); 37} else {38 NSLog (@ "person1 belongs to NSObject class "); 39} 40 41 // determine whether a method is in. whether to implement 42 if ([person1 respondsToSelector: @ selector (actionTow)]) {43 NSLog (@ "person1 implements actionTow "); 44} else {45 NSLog (@ "person1 does not implement actionTow"); 46}
This article GitHub address https://github.com/zhangkiwi/iOS_SN_NSObject