问题
just wondering, how do I convert List to Result?
Cause I'm doing filtering of region and areas, and when user selected region then area should show only those area in the region. And when I'm asigning my areas to a variable defined as var areas: Results<Area>!, I got the compile error
Cannot assign value of type 'List' to type 'Results!'
my code is as below
if let regionString = self.selectedRegionString {
let region = self.realm.objects(Region).filter("name = '\(regionString)'").first
self.areas = region!.areas //this line is the problem
} else {
self.areas = self.realm.objects(Area)
}
回答1:
I think you should define your self.areas like
var areas: List<Area>
It should have the same model class
Results is used for Realm's queries returned value.
来源:https://stackoverflow.com/questions/34326392/covert-realm-list-to-realm-result