简体   繁体   English

核心数据-NSString的NSSet

[英]Core Data - NSSet of NSString

Is it possible to have NSSet of NSString objects in a core data object? 是否可以在核心数据对象中包含NSString对象的NSSet

For example I have ClassA that is a subclass of NSManagedObject , I want that ClassA will hold a set of strings. 例如,我有ClassA ,它是NSManagedObject的子NSManagedObject ,我希望ClassA将保存一组字符串。

I know I can create some kind of ManagedString that is a subclass of NSManagedObject and use it, but I prefer not. 我知道我可以创建某种ManagedString并使用它,它是NSManagedObject的子类,但是我不喜欢。

If you set the type of an attribute to "Transformable" then you can simply assign an NSSet to it: 如果将属性的类型设置为“ Transformable”,则可以简单地为其分配一个NSSet

e.setOfStrings = [NSSet setWithObjects:@"a", @"b", @"c", nil];

Core Data will use the NSCoding methods to transform the set into a data blob and store that in the SQLite store. 核心数据将使用NSCoding方法将集合转换为数据Blob,并将其存储在SQLite存储中。

A disadvantage might be that you cannot search for strings in the set in a fetch request. 缺点是您无法在获取请求中搜索集合中的字符串。 If you need that feature then you have to use a to-many relationship instead. 如果需要该功能,则必须使用一对多关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM