iOS-OC-基礎-NSObject常用方法,ios-oc--nsobject

來源:互聯網
上載者:User

iOS-OC-基礎-NSObject常用方法,ios-oc--nsobject

 1     Person *person1 = [[Person alloc]init]; 2     Person *person2 = [[Person alloc]init]; 3      4 //    可以調用類中的私人方法,但是會有一個警告 5     [person1 performSelector:@selector(actionTow)]; 6     [person1 performSelector:@selector(actionOne:) withObject:@"test"]; 7      8     NSLog(@"person1的地址:%p",person1); 9     NSLog(@"person2的地址:%p",person2);10     11 //    比較兩個對象的地址是否相同12     if ([person1 isEqual:person2]) {13         NSLog(@"兩個對象地址相同");14     }else{15         NSLog(@"兩個對象地址不同");16     }17     18 //    判斷某個對象是否屬於某個類或者他的父類19     if([person1 isKindOfClass:[Person class]]){20         NSLog(@"person1屬於Person類");21     }22     23     if ([person1 isKindOfClass:[NSObject class]]) {24         NSLog(@"person1屬於NSObject類");25     }26     27     28 //    判斷某個對象是否屬於某個類,但是不能確定它的父類29     if([person1 isMemberOfClass:[Person class]]){30         NSLog(@"person1屬於Person類");31     }else{32         NSLog(@"person1屬不於Person類");33     }34     35     if ([person1 isMemberOfClass:[NSObject class]]) {36         NSLog(@"person1屬於NSObject類");37     }else{38         NSLog(@"person1屬不於NSObject類");39     }40     41 //    判斷某個方法是否在.m中是否實現42     if ([person1 respondsToSelector:@selector(actionTow)]) {43         NSLog(@"person1實現了actionTow");44     }else{45         NSLog(@"person1沒有實現了actionTow");46     }

 

本文GitHub地址https://github.com/zhangkiwi/iOS_SN_NSObject

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.