6、獲取乙個類的所有方法:
u_int count;
method * methods = class_copymethodlist([customclass class], &count);
for (int i = 0; i < count; i++)
//設定全域性變數的值
- (void) setinstancevar
9、判斷類的某個屬性的型別
- (void) getvartype else if ([stringtypehasprefix:@"i"]) else if ([stringtypehasprefix:@"f"]) else
}10、通過屬性的值來獲取其屬性的名字(反射機制)
- (nsstring *)nameofinstance:(id)instance
//reads the value of an instance variable in an object. object_getivar這個方法中,當遇到非objective-c物件時,並直接crash
if ((object_getivar(allobj, thisivar) == instance))
}free(ivars);
return key;
}測試**:
allobj= [classcustomclassnew];
allobj.vartest1=@"vartest1string";
allobj.vartest2=@"vartest2string";
allobj.vartest3=@"vartest3string";
nsstring *str = [selfnameofinstance:@"vartest1string"];
nslog(@"str:%@", str);
列印結果:
2013-07-26 16:26:26.271 highoc[7081:c07] str:vartest1
IOS高階開發 Runtime(三)
11 系統類的方法實現部分替換 void methodexchange 列印結果 仔細看log 2013 07 26 16 33 22.776 highoc 7104 c07 sssaaaass 2013 07 26 16 33 22.778 highoc 7104 c07 sssaaaass 12...
IOS高階開發 Runtime(三)
11 系統類的方法實現部分替換 void methodexchange 列印結果 仔細看log 2013 07 26 16 33 22.776 highoc 7104 c07 sssaaaass 2013 07 26 16 33 22.778 highoc 7104 c07 sssaaaass 12...
IOS高階開發 Runtime(一)
一些公用類 inte ce customclass nsobject void fun1 end implementationcustomclass void fun1 end inte ce testclass nsobject end implementationtestclass end 別忘...