CoreData 上的 UserInfo 字典

UserInfo Dictionaries on CoreData(CoreData 上的 UserInfo 字典)
本文介绍了CoreData 上的 UserInfo 字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

Apple 核心数据文档的这一部分是什么意思?

What does this part of Apple core data documentation means?

用户信息词典

托管对象模型中的许多元素(实体、属性和关系)都有关联的用户信息字典.您可以将所需的任何信息作为键值对放入用户信息字典中.放入用户信息字典的通用信息包括实体的版本详细信息,以及用于获取属性的谓词的值.

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.

我了解默认情况下实体具有该字典,但我无法在 coredata 实体或属性上找到 userInfo.

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

推荐答案

NSManagedObject 获取 NSEntityDescription(通过 entity 属性)或从您的 NSManagedObjectModel 并通过 attributesByName 获取 NSAttributeDescription.这为您提供了一个字典,您可以在其中按名称获取正确的描述,其中 userInfo 作为属性也是如此.

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"];

这篇关于CoreData 上的 UserInfo 字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Resume game cocos2d(恢复游戏 cocos2d)
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)
How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?(如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?)