Convert from Realm Results to Array produce empty objects

放肆的年华 提交于 2019-12-06 13:18:08

Try this:

let realm = try! Realm()
let requestsFromRealm = realm.objects(Request.self)
let requests = requestsFromRealm.toArray()

Using this extension:

extension Results {

    func toArray() -> [T] {
        var array = [T]()
        for result in self {
            array.append(result)
        }
        return array
    }
}
let requests = Array (requestsFromRealm)

I think that there is no problem with this code.

Is not "dynamic" missing in the property of Realm Object?

class Request: Object {
     dynamic var body: String = ""
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!