Covert realm list to realm result

半世苍凉 提交于 2020-01-03 19:29:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!