문제

Is it possible to have NSSet of NSString objects in a core data object?

For example I have ClassA that is a subclass of NSManagedObject, I want that ClassA will hold a set of strings.

I know I can create some kind of ManagedString that is a subclass of NSManagedObject and use it, but I prefer not.

도움이 되었습니까?

해결책

If you set the type of an attribute to "Transformable" then you can simply assign an NSSet to it:

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.

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top