Clifton Labrum
Clifton Labrum

Reputation: 14060

Search Realm Relationship in Swift 3

Swift 3, Realm 2.1

I'm trying to figure out how to search my Aircraft objects based on values in its related fieldValues list. Here is a simplified view of my class structure:

class Aircraft: Object {
  dynamic var makeModel = ""
  let fieldValues = List<FieldValue>()
}

class FieldValue: Object{
  dynamic var name = ""
}

I can search the makeModel value (where search! is my search term) like this:

let makeModelPredicate = NSPredicate(format: "makeModel BEGINSWITH[c] %@", search!)

...but how do I check to see if search matches any name values in the fieldValues list?

Upvotes: 0

Views: 261

Answers (1)

Thomas Goyne
Thomas Goyne

Reputation: 8138

You can query over key paths: NSPredicate(format: "ANY fieldValues.name = %@", search!)

Upvotes: 2

Related Questions