views:

23

answers:

1

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;

}
A: 

I never did figure out what was happening. I gave up, rebuilt the data model, and all was fine.

粪便猴子