IOS-OC-Basic-NSObject common method, ios-oc -- nsobject

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.