【发布时间】:2015-07-04 06:52:27
【问题描述】:
我有两个实体
书 - 属性:名称,描述 - 关系:类型为 To Many 的 book 到 BookLang(逆:bookLang)
BookLang - 属性:nameLang、descLang、lang - 关系:bookLang,类型为 To One to Book(逆:book)
在 BookLang 中有两个对象用于 fr,de 语言 如果我使用
let lang = "fr"
let pre = NSPredicate(format: "book.lang == %@", lang);
Then I have to loop through the fetchResult and then loop through the book NSSet
for b in bookSet {
let lan = b.valueForKey("lang") as! String
if(lan == lang){
let name = b.valueForKey("nameLang") as! String
println(name) // the book title in french
break;
}
}
我如何才能在书 NSSet 中只获取我想要的对象
我试试
let subPre = NSPredicate(format: "SUBQUERY(BookLang, $s, $s.lang == %@)", lang);
有错误
Unable to parse the format string "SUBQUERY(BookLang, $s, $s.lang == %@)"'
【问题讨论】: