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"
}
}
我有两个用于消息的一个类,另一个用于用户,每个用户都有一个消息列表,我需要根据(UserRealm.sender)查询该消息 This is the realm DB
答案 0 :(得分:0)
如果有人面对同样的话,我会通过这种方式解决问题
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")
}