After I convert my project from swift 2.3 to swift 3 , I got this error in Realm Filter I can't get filter result in array :
func filterUsers(_ searchText: String, completion: (([Lawyer]) -> Void)) {
let bgRealm = try! Realm() // Filter the whole list of users
let results = bgRealm.objects(Lawyer.self).filter { (cc) -> Bool in
cc.name.contains2(searchText) ||
cc.name.contains2(searchText) ||
cc.phoneNumber2.contains2(searchText)
}
print(results)
completion(results)
}
filter
,map
, etc. are lazy operations on theResults
returned byobjects
. This is implemented in types such asLazyFilterBidirectionalCollection<T>
. To actually perform the filtering and get an array of results, you need to promote this collection to an array by wrapping in an Array initializer (e.g.Array(bgRealm.objects...))
From the docs: