Underbelly Project: Hidden Art Show in Abandoned Subway Station
nytimes.com1 pointsby Zev0 comments
@interface MYObject : NSObject
@property (nonatomic, copy) NSString *foo;
@property (nonatomic, copy) NSString *bar;
@end
@implementation MYObject
@end
And somewhere else in your code: - (MYObject *) buildMYObject {
MYObject *object = [[MYObject alloc] init];
[object setValuesForKeysWithDictionary:@{ @"foo": @"purple", @"bar": @"elephant" }];
return object;
}
Then you can access it like a regular property: - (void) useMYObject {
MYObject *builtObject = [self buildMYObject];
NSLog(@"value: %@", builtObject.foo); // will print "value: purple"
NSLog(@"value: %@", builtObject.bar); // will print "value: elephant"
}
There are some gotchas to be aware of here (that Parse likely takes care of, since you're subclassing PFObject), such as setting nil values, or attempting to set the value from a key that doesn't have a corresponding property on your object.