如何获取Core Data中的关系项属性? [英] How to get at a relationship items properties in Core Data?
问题描述
假设你有一个名为Workshop的核心数据对象。
如何在Workshop中创建学生的NSArray?
这是一个与数组相反的NSSet,因为它们是无序的。使用mutableSetValueForKey:这个
返回一个代理,它会改变
关系并执行KVO
通知。想想名字为
[NS] MutableSetvalueForKey而不是b的b比mutableSetValueforKey,
因为它返回一个可变集合
你操作
NSMutableSet *学生;
Students = [Workshop mutableSetValueForKey:@Students];
[Students addObject:newStudent];
[Students removeObject:oldStudent];
Say you have a Core Data object called Workshop. It has a to-many relationship to a Student object.
How would I create an NSArray of the students within the Workshop?
It's a NSSet opposed to an array, as they are unordered.
Use mutableSetValueForKey: This returns a proxy that mutates the relationship and does KVO notifications. Think of the name as "[NS]MutableSet" "valueForKey" rather than "mutableSetValue" "forKey", because it returns a mutable set that you manipulate
NSMutableSet *Students; Students = [Workshop mutableSetValueForKey: @"Students"]; [Students addObject: newStudent]; [Students removeObject: oldStudent];
这篇关于如何获取Core Data中的关系项属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!