Does a Core Data NSSet contain an object with a certain ID?

我是研究僧i 提交于 2019-12-22 01:16:19

问题


I have a Core Data object that contains an NSSet of other objects (e.g. Library object contains NSSet of Books). What's the best way to check if an instance of Library contains a book with a certain bookID?

Is it possible to be done with Key Value coding or do I have to enumerate all books and check them manually?


回答1:


Yes, you can use KVC for this.

BOOL bookExists = [[set valueForKey:@"bookID"] containsObject:@"myBookID"];


来源:https://stackoverflow.com/questions/7256909/does-a-core-data-nsset-contain-an-object-with-a-certain-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!