Array of NSManagedObject attributes

前端 未结 2 1745
离开以前
离开以前 2021-02-08 18:06

I\'d like to get an array of the attributes for my NSManagedObject so I can use KVO to export them. I can create an array manually and then iterate through it, howe

相关标签:
2条回答
  • 2021-02-08 19:00

    An NSManagedObject has an entity associated with it. Use NSEntityDescription's -attributesByName and -relationshipsByName. You'll get a dictionary back from each of those methods. Just ask the dicts for their -allKeys.

    0 讨论(0)
  • 2021-02-08 19:08

    Thanks Joshua. Here's code that I used in case any one would like to see a hard example:

    NSString *entityName = NSStringFromClass([myEntity class]);
    NSEntityDescription *entityDescription = [self entityDescriptionWithEntityName:entityName];
    NSDictionary *attributes = [entityDescription attributesByName];
    NSArray *attributeNames = attributes.allKeys;
    
    0 讨论(0)
提交回复
热议问题