当我想过滤我的数据时,我收到错误 *** 由于未捕获的异常“无效的属性名称”而终止应用程序,原因:“在“书”类型的对象中找不到“属性”。我的结构:
class Book: Object, Codable {
@objc dynamic var author = ""
@objc dynamic var title = ""
@objc dynamic var imageLink = ""
@objc dynamic var category = "Lk"
@objc dynamic var date = Date()
convenience init(withBookDict: [String: Any]) {
self.init()
self.author = withBookDict["author"] as? String ?? "No Author"
self.title = withBookDict["title"] as? String ?? "No Title"
self.imageLink = withBookDict["imageLink"] as? String ?? "No link"
self.category = withBookDict["category"] as? String ?? "No category"
}
}
我过滤数据的代码是这样的:
let filteredread = realm.objects(Book.self).filter({ $0.category == "read"})
但我也试过这个:
let filteredread = realm.objects(Book.self).filter("category == 'read'")
由于存在版本问题,我也确实更新了我的领域 pod。