The code is easy to understand, but output is not.
Screen of xcdatamodel editor:
The type of deleted
is String
.
@interface Row : NSManagedObject
(...)
@property (nonatomic, retain) NSString * deleted;
@end
@implementation Row
(...)
@dynamic deleted;
@end
Somewhere else in code:
Row *row = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString* fixedTypeDeletedClassString = NSStringFromClass([row.deleted class]);
NSString* KVCDeletedClassString = NSStringFromClass([[row valueForKeyPath:@"deleted"] class]);
NSLog(@"%@ is %@", row.deleted, fixedTypeDeletedClassString);
NSLog(@"%@ is %@", [row valueForKeyPath:@"deleted"], KVCDeletedClassString);
The output is:
2014-05-07 17:29:26.170 iOSplayground[20814:90b] false is __NSCFString
2014-05-07 17:29:26.171 iOSplayground[20814:90b] 0 is __NSCFNumber
Why the class of the property is different?
Class is different, but at least looks like properly casted, but there is a worse case:
2014-05-07 17:29:26.172 iOSplayground[20814:90b] true is __NSCFString
2014-05-07 17:29:26.172 iOSplayground[20814:90b] 0 is __NSCFNumber
I've been fast prototyping without Row class at first, and used NSManagedObject
with KVC, and I've lost a lot of time on debuging why there is a property of class that I didn't use.