Realm: Results als List

前端 未结 3 1078
小蘑菇
小蘑菇 2021-02-13 22:17

Is it possible to convert Results to List or shouldn\'t I do this?

In my case I have method that has List as a parameter. I w

3条回答
  •  醉话见心
    2021-02-13 22:31

    Results implements the CollectionType protocol so you could use reduce to convert it:

    let results: Results = ...
    let converted = results.reduce(List()) { (list, element) -> List in
        list.append(element)
        return list
    }
    

    You could put this code in an extension or however you like.

提交回复
热议问题