开发者

How can I iterate over a class keys in objective-C?

开发者 https://www.devze.com 2023-03-30 05:11 出处:网络
How can I iterate over an instance properties in objective-C ? I need to get all the properties values 开发者_JAVA技巧without having to specify them.

How can I iterate over an instance properties in objective-C ?

I need to get all the properties values 开发者_JAVA技巧without having to specify them.

This is the only solution I've found so far, but I was wondering if it could be done with less code: Get an object properties list in Objective-C

thanks


EDIT : @EmptyStack has the right idea - follow his link in the comments on the question :)


Take a look at these methods : http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/c/func/class_copyPropertyList

They let you (amongst other things) find all the properties that a class implements. You can then run through that array of properties and call performSelector: for each property you are interested in.

0

精彩评论

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

关注公众号