Can someone post an example of how I get an instance variable value that is a double?
I tried using the object_getIvar() function but that didn’t go very well because it seems like this function is only good for variables that return objects and not scalar data type.
Can someone post an example of how I get an instance variable value that
Share
If you already know the name of the instance variable, you can just use KVC. Say the ivar with double value of an object x is called “weight”, you do
NSNumber* x=[obj valueForKey:@"weight"];then you can get the double value by[x doubleValue].Similarly, you can set an NSNumber num containing a double value by
[obj setValue:num forKey:@"weight"].object_getIvar()is something lower-level, useful to get the class layout and/or getting the type information of an ivar which you only know the name, etc. If KVC isn’t sufficient for you, could you explain in more detail exactly what you want to achieve?