我正在尝试使用索引1加载Name,但是它不起作用(CollectionView为空)。
CoreData :
LoadData:
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
let managedContext = appDelegate.persistentContainer.viewContext
let fetchRequestTag = NSFetchRequest<NSManagedObject>(entityName: "Tag")
let PreValue = 1
let predicate = NSPredicate(format: "index == %i", PreValue)
fetchRequestTag.predicate = predicate
do {
tagItems = try managedContext.fetch(fetchRequestTag)
} catch let error as NSError {
print("Could not fetch. \(error), \(error.userInfo)")
}
TagCollectionView.reloadData()
TagCollectionView.selectItem(at: NSIndexPath(item: 0, section: 0) as IndexPath, animated: false, scrollPosition: [])
for data in tagItems {
print("\(data.value(forKey: "name") as! String as Any), \(NSKeyedUnarchiver.unarchiveObject(with: data.value(forKeyPath: "index") as! Data) as! Int)")
}
答案 0 :(得分:3)
属性类型和谓词类型不匹配。
Transformable
作为 index 的类型还是毫无意义的。将属性类型设置为Int32
,或者将0
和1
的索引设置为Bool
。