【问题标题】:Realm query not working with list领域查询不适用于列表
【发布时间】:2017-03-18 13:03:04
【问题描述】:

我有两个 Realm 对象 Location 和 Sector。定义如下:

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 = ""
}

我正在尝试使用以下方法创建一个位置内的扇区查询

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

如果我在打印语句中执行此操作,我可以看到我有正确的位置。但是部门正在返回所有部门,包括其他位置的部门。

有什么想法吗?

【问题讨论】:

  • 嗯,该代码看起来正确,所以我想知道您的数据保存方式是否存在问题。您能否在 Realm 浏览器中打开您的 Realm 文件并发布您的 Location 对象之一的屏幕截图?

标签: swift3 realm realm-list


【解决方案1】:

有点奇怪。我关闭了 Xcode,重新打开,一切正常...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多