Can we get an ivar
or a property
from a NSString
like we can get a class
from a NSString
with the function NSClassFromNSString()
?
Asked
Active
Viewed 1,360 times
4

klefevre
- 8,595
- 7
- 42
- 71
-
Just wondering: what would you need this for? What use is it? – Itai Ferber Jun 08 '11 at 23:50
-
Yes, I could change my design pattern but I just want to know if it is possible. – klefevre Jun 08 '11 at 23:53
2 Answers
8
For any properties you can just use [object valueForKey:myString]
and it'll be done. This can also find ivars in certain situations.

Abizern
- 146,289
- 39
- 203
- 257

Joshua Weinberg
- 28,598
- 2
- 97
- 90
-
1I’ve posted an answer to [this question](http://stackoverflow.com/q/5784875/557219) showing how to obtain ivars using the Objective-C runtime. – Jun 09 '11 at 00:04
3
There are a number of functions in the Objective-C Runtime that let you get the list of ivars, properties, and methods associated with a given class, and then to get information about individual ivars, properties, and methods. Take a look at the Objective-C Runtime Reference.

Caleb
- 124,013
- 19
- 183
- 272
-
Nice list of functions but that was not exactly what I needed, thanks anyway. – klefevre Jun 09 '11 at 00:14