0
我需要在桌面视图中显示结果witch是唯一的,根据距离我的位置排序....然后使用过滤器。我正在用函数“.filter()”使用这个框架和函数,但它似乎不起作用。SWIFT RealmGeoQueries使用过滤器
private func distanceRealm(){
//get all points closest to me
let myLocation = CLLocationCoordinate2DMake(Double(LocationManager.sharedInstance.latitude)!, Double(LocationManager.sharedInstance.longtitude)!)
StoredData.sharedInstance.sortedObjectsByDistance = try! Realm().objects(E21.self).filter("Id_prov != ''").filterGeoRadius(myLocation, radius: 50000, sortAscending: true)
//leave just unique values
var seenIdProv:[String:Bool] = [:]
StoredData.sharedInstance.sortedObjectsByDistance = StoredData.sharedInstance.sortedObjectsByDistance.filter {
seenIdProv.updateValue(false, forKey: $0.Id_prov) ?? true
}
print(StoredData.sharedInstance.sortedObjectsByDistance)
}
正如你可以看到我有这个概率。
.filter("Id_prov != ''")
这让我犯错:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "Id_prov != ''"'
所以如何使用过滤器?