since we know that the properties of NSFetchRequestToFetch can limit the required properties, this can reduce the amount of memory. If we do it like this:
request.propertiesToFetch = [NSArray arrayWithObjects:@"nID", nil];
and
NSString *strID = [NSString stringWithFormat:@"%@", aPerson.nID]; cell.textLabel.text = strID;
then debug output (not fire error):
CoreData: sql: SELECT t0.Z_ENT, t0.Z_PK, t0.ZNID FROM ZPERSON t0 ORDER BY t0.ZNID
A strange thing happened, however, when I add a new unmodeled property to a subclass of NSManagedObject Person. Similar:
@interface Person (Ex) @property (nonatomic, retain) NSString *strTempName; @end @implementation Person (Ex) @dynamic strTempName; -(void)setStrTempName:(NSString *)strTempName { [self setPrimitiveValue:strTempName forKey:@"strTempName"]; } -(NSString*)strTempName { return [self primitiveValueForKey:@"strTempName"]; }
And here a new unmodeled property opens:
NSString *strTT = aPerson.strTempName;
then debug output:
2013-05-06 10:43:07.789 TestCoreData[988:c07] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZBISFORTEST, t0.ZBISINTRASH, t0.ZNID, t0.ZSTRNAME, t0.ZSTROK, t0.ZSTROK2, t0.ZSTRTEST1, t0.ZSTRTEST2, t0.ZADEPART, t0.ZAMIDDLETHUMNAIL, t0.ZANORMALPIC, t0.ZASMALLTHUMNAIL FROM ZPERSON t0 WHERE t0.Z_PK = ? 2013-05-06 10:43:07.790 TestCoreData[988:c07] CoreData: annotation: sql connection fetch time: 0.0010s 2013-05-06 10:43:07.791 TestCoreData[988:c07] CoreData: annotation: total fetch execution time: 0.0018s for 1 rows. 2013-05-06 10:43:07.792 TestCoreData[988:c07] CoreData: annotation: fault fulfilled from database for : 0x898a030 <x-coredata://CAD35D43-F6B2-4463-B59B-C9A3CD488935/Person/p51846>
From the output message above we can find a non-model property caused by the fact that instead of SELECT t0.Z_ENT, t0.Z_PK, t0.ZNID, SELECT all property sentences are generated and an error is triggered!
however, I read a few posts about the unmodeled property ( here is the link ):
Because unmodeled properties are only attributes of a custom NSManagedObject Subclass, not an object, failure objects know nothing about them. Damage objects are initialized from the data model so that all keys to which they respond must be in the data model. This means that faults will not reliably respond to a request for unmodeled properties.
why did the strange happen?
early.
@Anonymous,
choice 1): the application crashed and the debug output showed:
2013-05-06 14:03:05.665 TestCoreData[1794:c07] -[Person strTempName]: unrecognized selector sent to instance 0x6ba77b0 2013-05-06 14:03:30.395 TestCoreData[1794:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Person strTempName]: unrecognized selector sent to instance 0x6ba77b0'
2) choice: firstly, methods like willAccessValueForKey, etc., should send a KVO change notification, just like comments in NSManagedObject.h:
- (void)willAccessValueForKey:(NSString *)key;
secondly, the next choice is 2) the code, the strange thing (for troubleshooting) is still alive in my application.
also thanks to your answer.