Search code examples
swift3realmrealm-list

Realm query not working with list


I have two Realm objects Location and Sector. that are defined in the following way:

class Location: Object {

  dynamic var id = ""
  dynamic var cityarea = ""
  let sectors = List<Sector>()

  override static func primaryKey() -> String? {
    return "id"
  }
}

class Sector: Object {
  dynamic var sector = ""
}

I am trying to create a query of sectors within a location using the following method

let location = uiRealm.objects(Location.self).filter("cityarea = '\(valCity)'").first
sectors = location?.sectors.sorted(byKeyPath: "sector", ascending: true)
print("sectors: \(sectors)")
print("location \(location)")

If I do this in the print statement I can see that I have the correct location. However sectors is returning ALL sectors, including those in other locations.

any thoughts?


Solution

  • All a bit strange. I closed down Xcode, re-opened, all worked well...