#import"NSObject+RunTimeUtility.h"
#import<objc/runtime.h>
@implementationNSObject(RunTimeUtility)
-(id)getPrivateProperty:(NSString*)propertyName
{
IvariVar=class_getInstanceVariable([selfclass],[propertyNameUTF8String]);
if(iVar==nil){
iVar=class_getInstanceVariable([selfclass],[[NSStringstringWithFormat:@"_%@",propertyName]UTF8String]);
}
idpropertyVal=object_getIvar(self,iVar);
returnpropertyVal;
}
@end
1,運用KVC方式訪問
這種方式之前在中提到過,詳細的就不多說了,用法很復雜:
id view = [self valueForKey:@“controlView"];
2,運用運轉時
id
view;Ivarivar=class_getInstanceVariable([selfclass],[@"controlView"UTF8String]);view=object_getIvar(self,ivar);
【獲取公有屬性】的相關資料介紹到這裡,希望對您有所幫助!
提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!