I am using a Realm List/Results
as my dataSource for a UITableView
. At some point I assign a list to it. like:
var dataSource:List<SomeObject>! // Or >> Results<SomeObject>!
let aRealmObject = realm.objectForPrimaryKey(SomeObject.self, key: objectId)
dataSource = aRealmObject.someList // dataSource should be List
Then I have a filter on this list If the user changed the filter dates, I do like this:
dataSource = dataSource.filter("FILTER THE DATES",newDates) // dataSource should be Results
But the line above causes an error as the return type of filter
is a Results
object and aRealmObject.someList
is a List.
What is the best way to deal with this situation?
List
and convert the Results
object to List
? How??Results
and convert the List
to Results
? How??Thanks,
Both List
and Results
(as well as LinkingObjects
) can be converted into an AnyRealmCollection
type. I think this is probably the best way to standardize all of Realm's array-type types:
var dataSource:AnyRealmCollection!
let aRealmObject = realm.objectForPrimaryKey(SomeObject.self, key: objectId)
dataSource = AnyRealmCollection(aRealmObject.someList)