0

如果我创建了一个字符串数组(通过键值编码),其中包含第一次存储在 App Delegate 中的托管对象实体的属性的名称,我得到一个 NSStrings 数组,没有任何问题。如果我随后从代码中的相同入口点进行相同的调用,则相同的集合将成为 NULL 对象的数组——即使核心数据上下文中没有任何变化。

一个不吸引人的解决方法是每次都重新创建字符串数组,但我想知道是否有人猜测幕后发生的事情。

// 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;

}
4

1 回答 1

0

我从来没有弄清楚发生了什么。我放弃了,重建了数据模型,一切都很好。

于 2010-05-07T04:44:44.810 回答