UserInfo Dictionaries on CoreData

穿精又带淫゛_ 提交于 2019-11-30 02:37:43

问题


What does this part of Apple core data documentation means?

User Info Dictionaries

Many of the elements in a managed object model—entities, attributes, and relationships—have an associated user info dictionary. You can put whatever information you want into a user info dictionary, as key-value pairs. Common information to put into the user info dictionary includes version details for an entity, and values used by the predicate for a fetched property.

I understand that by default entities have that dictionary, but I'm not able to find find userInfo on coredata entities or attributes.


回答1:


Get the NSEntityDescription from your NSManagedObject (through the entity property) or from your NSManagedObjectModel and get the NSAttributeDescription through attributesByName. This gives you a dictionary where you get the proper Description by name which has the userInfo as a property as well.

NSManagedObject *managedObject;
NSEntityDescription *entityDescription = managedObject.entity;
NSAttributeDescription *attributeDescription = entityDescription.attributesByName[@"someAttribute"];
NSString *foo = attributeDescription.userInfo[@"foo"];


来源:https://stackoverflow.com/questions/17230614/userinfo-dictionaries-on-coredata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!