NSManagedObject属性数组

我想获得我的NSManagedObject的属性数组,所以我可以使用KVO导出它们。 我可以手动创build一个数组,然后遍历它,但是,我想自动获取这个列表,然后迭代。

一个NSManagedObject有一个与之关联的实体。 使用NSEntityDescription的-attributesByName-relationshipsByName 。 你会从这些方法中得到一本字典。 只要问问他们的所有-allKeys

感谢Joshua。 以下是我使用的代码,以防有人想看到一个难题:

 NSString *entityName = NSStringFromClass([myEntity class]); NSEntityDescription *entityDescription = [self entityDescriptionWithEntityName:entityName]; NSDictionary *attributes = [entityDescription attributesByName]; NSArray *attributeNames = attributes.allKeys;