3

I am using Realm for Swift. I have two Realm objects structures like this:

class outerObject : Object {
   dynamic var innerObject : innerInfo?
}

class innerInfo : Object {
  dynamic var sortId = 5
}

I want to make a query that gets every outerObject where the innerInfo is not nil and sortId equals 3. Normally I would use something like:

realm.objects(outerObject).filter(predicate)

And then write a suitable NSPredicate but I do not hink that works with optionals. So what is the recommended method?

blackpool
  • 485
  • 2
  • 8
  • 16

2 Answers2

4

This query should work: realm.objects(outerObject).filter("innerObject.sortId = 3").

jpsim
  • 14,329
  • 6
  • 51
  • 68
-2

when innerObjc is nil, this will been broken. Expected object of type string for property '' on object of type '', but received: (null),the 2nd anwser is not the right anwser.

kzhiquan
  • 1
  • 1