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忽略屬性的領域不應該像那樣..所以什麼是一個適當的解決方案,我的問題得到的結果添加到數組中的附加屬性?轉換爲普通對象?