![](/img/trans.png)
[英]How to implement show/hide sections in collectionview with swift
[英]How to show multiple categories per category in a collectionView in Swift?
我需要在Collection View中為每個類別顯示多個類別,因為在CoreData中,一個類別有許多類別,並且在編寫此行時類別設置為NSset類型
fetchRequest.predicate = NSPredicate(format: "category.categories == %@", (category?.categories!)!)
它拋出一個錯誤CoreData:錯誤:SQLCore dispatchRequest:異常處理請求:,這里不允許使用userInfo(null)的to-many鍵
每次需要在獲取時進行過濾,您不必使用NSPredicate
的格式字符串(但這是最便宜的解決方案 - 請記住)。
您可以使用predicateWithBlock
初始化程序:
fetchRequest.predicate = NSPredicate { object, bindings -> Bool in
guard let object = object as? Category else { return false }
return object.categories == category?.categories
}
甚至是Array.filter
:
guard let allCategories = try? moc.executeFetchRequest(fetchRequest) as? [Category] else { return }
let result = allCategories.filter { $0.categories == category?.categories }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.