RealmSwift: Convert Results to Swift Array

前端 未结 11 1827
[愿得一人]
[愿得一人] 2020-12-12 15:50

What I want to implement:

class func getSomeObject() -> [SomeObject]? {
    let objects = Realm().objects(SomeObject)

    return objects.count > 0 ? o         


        
11条回答
  •  执念已碎
    2020-12-12 16:41

    If you absolutely must convert your Results to Array, keep in mind there's a performance and memory overhead, since Results is lazy. But you can do it in one line, as results.map { $0 } in swift 2.0 (or map(results) { $0 } in 1.2).

提交回复
热议问题