开发者

using objective c runtime functions in iOS app

开发者 https://www.devze.com 2023-03-25 10:03 出处:网络
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:

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_   //开发者_JS百科 ivar was CGFloat fontsize_; property was (nonatomic) CGFloat fontSize;

I can then parse that string, i.e. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号