Unexpected key-value behavior in a Core Data Context

Posted by ???? on Stack Overflow See other posts from Stack Overflow or by ????
Published on 2010-04-26T00:20:30Z Indexed on 2010/04/26 0:23 UTC
Read the original article Hit count: 228

If I create an array of strings (via key-value coding) containing the names of a Managed Object entity's attributes which are stored in the App Delegate the first time, I get an array of NSStrings without any problems. If I subsequently make the same call later from the same entry point in code, that same collection becomes an array of NULL objects- even though nothing in the Core Data Context has changed.

One unappealing work-around involves re-creating the string array every time, but I'm wondering if anyone has a guess as to what's happening behind the scenes.

// Return an array of strings with the names of attributes the Activity entity
- (NSArray *)activityAttributeNames {

#pragma mark ALWAYS REFRESH THE ENTITY NAMES?
  //if (activityAttributeNames == nil) {    
    // Create an entity pointer for Activity
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Activity" inManagedObjectContext:managedObjectContext];
    NSArray *entityAttributeArray = [[NSArray alloc] initWithArray:[[entity attributesByName] allValues]];

    // Extract the names of the attributes with Key-Value Coding
    activityAttributeNames = [entityAttributeArray valueForKeyPath:@"name"];
    [entityAttributeArray release];
  //}

  return activityAttributeNames;

}

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about core-data