简体   繁体   中英

using objective c runtime functions in iOS app

I want to get at the types of the properties of my objective C classes. I see I can do this by using the runtime function property_getAttributes(property), which returns a C string like this:

    T@"UIColor",&,N,VsomeColor_   // ivar was UIColor* someColor_; property was (nonatomic, retain) UIColor* someColor; 

or this:

    Tf,N,vfontSize_   // ivar was CGFloat fontsize_; property was (nonatomic) CGFloat fontSize;

I can then parse that string, ie look at the part after the initial T and before the following comma.

My question is -- is doing it this way likely to be stable? Or is there a better way?

property_getAttributes is part of the Objective-C runtime, as described here .

If you want to gain some kind of introspection about ObjC classes, it is the way to go. I don't think this is unstable, since the Objective-C runtime itself is quite stable. Furthermore there is an official guide (see link above) so you can trust it to be as stable as any other official Apple API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM