Say I have 2 managed objects in my model: Department
and Employee
(as discussed in the Core Data Programming Guide). If I alrea开发者_JAVA技巧dy have a specific department retrieved, I know I can get all employees in that department through
NSSet *departmentsEmployees = aDepartment.employees;
but what if I want to find a specific employee (e.g. with employeeId = 123) in that set, change one of its attributes, then save the change? How do I do that? Can I do a targeted query on the set? Or would I have to loop through each employee to find the one I want?
It seems that it would be better to try to find it in the employees
NSSet instead of doing a whole new query to the entire data model because I already have a specific department.
Thank you
One way to narrow the search is to use -[NSSet filteredSetUsingPredicate:]
.
精彩评论