2015-02-09 34 views
0

我正在尝试使用带有忽略属性的Realm。其实很像这篇文章 http://www.raywenderlich.com/81615/introduction-to-realm distance它被声明为一个模型属性,但实际上并没有被持久化和暂时使用来计算和显示。在新的RLMArray中使用Realm的非持久性属性

然后,我有这样的事情

func calculateDistance(stops:RLMResults) -> RLMArray { 
    let currentLocation = getCurrentLocation() 
    var results:RLMArray = RLMArray(objectClassName: Stop.className()) 
    for (var i = 0; i < Int(stops.count); i++) { 
     var stop = stops[UInt(i)] as Stop 
     let stopLocation = CLLocation(latitude: stop.coordinates.latitude, longitude: stop.coordinates.longitude) 
     let distance = currentLocation.distanceFromLocation(stopLocation) 
     if kDistanceMeters >= distance { 
      println("Distance to \(stop.stopName) --> \(distance) m ---- max(\(Int(kDistanceMeters))") 
      realm.beginWriteTransaction() 
      stop.distance = Double(distance) 
      results.addObject(stop) 
      realm.commitWriteTransaction() 
      println(stop.distance) // Prints out the distance. It's in the object 
     } 
    } 
    println("Getting the results") 
    println(results) // Distance property isn't there ... 
    return results 
} 

基本上我想使用这个新的临时results RLMArray,只显示我想在查看结果,与distance财产。 属性实际上分配在对象上,但是一旦在RLMArray中它就会消失。我没有得到任何错误顺便说一句。

我也阅读了stackoverflow忽略属性的领域不应该像那样..所以什么是一个适当的解决方案,我的问题得到的结果添加到数组中的附加属性?转换为普通对象?

回答

0

现在,您将需要创建您自己的按最近距离排序的对象的NSArray。您现在只能查询持久属性。

相关问题