如何获取Core Data中的关系项属性? [英] How to get at a relationship items properties in Core Data?

查看:144
本文介绍了如何获取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];

source

这篇关于如何获取Core Data中的关系项属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆