Update:
I have boiled the issue down to simply not being able to use key value coding on a class I made seen below
#import <Foundation/Foundation.h>
#import <GLKit/GLKit.h>
@interface CMTransformation : NSObject
@property(nonatomic) GLKVector3 position;
@property(nonatomic) GLKVector3 scale;
@property(nonatomic) GLKVector3 rotation;
@property(nonatomic) GLKVector3 anchor;
@property(nonatomic) GLKMatrix4 matrix;
- (GLKMatrix4)calculateMatrixWithParentTransformation:(CMTransformation *)parentTransformation;
@end
It has been my understanding and expience that I should be able to grab non NSObjects out as NSValues, however, I am finding it impossible to access these items (which are defined as unions) using KVC syntax:
CMTransformation* trans = [[CMTransformation alloc] init];
temp = [trans valueForKey:@"position"];
Similarly, if I try to access the underlying variable:
CMTransformation* trans = [[CMTransformation alloc] init];
temp = [trans valueForKey:@"_position"];
Both of these throw an exception because the key is not found. What am I missing here?
Previous Question
I have written some code which allows me to access a (somewhat) arbitrary structure with a string such as "transformation.position"
For some reason the code stops working on the second jump when I am trying to read a property from an NSObject. Here is the
NSString* property = actionDetails[@"Property"];
PropertyParts = [[property componentsSeparatedByString:@"."] mutableCopy];
int count = [PropertyParts count];
id current_object = initial_object;
for(int i = 0; i < count; i++)
{
NSString* current_part = PropertyParts[i];
current_object = [current_object valueForKey:current_part];
}
I have tried all possible syntax for property access including Property, property and _property.
Here is the custom NSObject declaration
#import <Foundation/Foundation.h>
#import <GLKit/GLKit.h>
@interface CMTransformation : NSObject
@property(nonatomic) GLKVector3 position;
@property(nonatomic) GLKVector3 scale;
@property(nonatomic) GLKVector3 rotation;
@property(nonatomic) GLKVector3 anchor;
@property(nonatomic) GLKMatrix4 matrix;
- (GLKMatrix4)calculateMatrixWithParentTransformation:(CMTransformation *)parentTransformation;
@end
Additionally, I can see after the first loop that the debugger says that CMTransformation* is populating currrent_object, so I am at a loss as to why I can't access its properties?
Would you be satisfied with implementing valueForUndefinedKey: and setValue:forUndefinedKey:?
If so, this works:
(Paste it into your main.m file to try)