用户登录
用户注册

分享至

CoreData 上的 UserInfo 字典

  • 作者: 犀牛鳄鱼V
  • 来源: 51数据库
  • 2022-12-30

问题描述

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.

推荐答案

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

Get the NSEntityDescription from your N**anagedObject (through the entity property) or from your N**anagedObjectModel 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.

N**anagedObject *managedObject;
NSEntityDescription *entityDescription = managedObject.entity;
NSAttributeDescription *attributeDescription = entityDescription.attributesByName[@"someAttribute"];
NSString *foo = attributeDescription.userInfo[@"foo"];
软件
前端设计
程序设计
Java相关