从领域列表中查询对象
query Object from Realm List
enter image description here我正在尝试从领域中查询对象
class MessageRealm: Object {
dynamic var fromId = String()
dynamic var messageID = String()
dynamic var textDownloadded = String()
override class func primaryKey() -> String? {
return "messageID"
}
}
class UsersRealm: Object {
dynamic var sender = String()
let msgs = List<MessageRealm>()
override class func primaryKey() -> String? {
return "sender"
}
}
我有两个 class 一个用于消息,另一个用于用户,每个用户都有一个消息列表,我需要根据 (UserRealm.sender) 查询该消息
This is the realm DB
如果有人遇到同样的问题,我就是这样解决的
var messageIndex: Results<MessageRealm>!
let realm = try! Realm()
let mssagesRealm = realm.objects(UsersRealm.self).filter("sender = %@", userTitleName)
for sub in mssagesRealm {
messageIndex = sub.msgs.sorted(byKeyPath: "timeStamp")
}
enter image description here我正在尝试从领域中查询对象
class MessageRealm: Object {
dynamic var fromId = String()
dynamic var messageID = String()
dynamic var textDownloadded = String()
override class func primaryKey() -> String? {
return "messageID"
}
}
class UsersRealm: Object {
dynamic var sender = String()
let msgs = List<MessageRealm>()
override class func primaryKey() -> String? {
return "sender"
}
}
我有两个 class 一个用于消息,另一个用于用户,每个用户都有一个消息列表,我需要根据 (UserRealm.sender) 查询该消息 This is the realm DB
如果有人遇到同样的问题,我就是这样解决的
var messageIndex: Results<MessageRealm>!
let realm = try! Realm()
let mssagesRealm = realm.objects(UsersRealm.self).filter("sender = %@", userTitleName)
for sub in mssagesRealm {
messageIndex = sub.msgs.sorted(byKeyPath: "timeStamp")
}