I want to get query works.
Always get crash...
Terminating app due to uncaught exception 'Invalid property name', reason: 'Property 'New' not found in object of type 'Item''
I have object with properties:
dynamic var categoryTitle = ""
dynamic var isNew: Bool = false
Then I try to query them:
let realm = try! Realm()
newItems = realm.objects(Item.self).filter("isNew = \(true) AND categoryTitle = \(category.title)")
If I use next query - everything is work fine, but I need complex query:
newItems = realm.objects(Item.self).filter("isNew = \(true)")
Don't know why Realm search property with name New instead of isNew. May be it depends of Swift version - I use Swift 3.
Realm version: 2.1.0
Xcode version: 8.1 (8B62)
iOS/OSX version: iOS 10.1
Dependency manager + version: CocoaPods
It looks like the value of category.title is treated as property not the string. Try to specify your query like this:
// NOTE: this could lead to error if category.title contains \' use the second example instead
.filter("isNew = '\(true)' AND categoryTitle = '\(category.title)'")
or, the recommended way:
.filter("isNew = true AND categoryTitle = %@", category.title)
Oh! Thanks! It works.
But any way behavior is strange...
Awesome! Learn more about queries in docs at https://realm.io/docs/swift/latest/#queries.
Most helpful comment
It looks like the value of
category.titleis treated as property not the string. Try to specify your query like this:or, the recommended way: