Kingdom: Results <T> als List <T>
Is it possible to convert Results<T> to List<T> or should I not do this?
In my case, I have a method that has List as a parameter. I want to call this method with the extracted objects ( Results<T> ) and with the computed objects ( List<T> )
Results and List implement CollectionType and RealmCollectionType . The latter is a specialization of the first protocol, which allows you to efficiently use the aggregation functions and filter and sort records.
Almost no method in Realm Swift makes serious assumptions about the type of collection. They simply expect a SequenceType , which is a generalization of the first CollectionType . For your own method, I would recommend going the same way. You can achieve this by declaring it as shown below.
func foo<T, S: SequenceType where S.Generator.Element == T>(objects: S) { … } Results implements the CollectionType protocol, so you can use reduce to convert it:
let results: Results<MyObject> = ... let converted = results.reduce(List<MyObject>()) { (list, element) -> List<MyObject> in list.append(element) return list } You can put this code in an extension or as you like.