我的託管對象有兩個雙字段:「緯度」,「經度」。 我需要獲取的所有對象,具有一定的座標NSPredicate不使用double值(%f)?
此代碼不能正常工作,fetchedObjects數= 0
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"latitude == %f AND longitude == %f", coordinate.latitude, coordinate.longitude];
但這個代碼做工精細,fetchedObjects數= 3:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"latitude == 53.012667 AND longitude == 36.113000"];
接受你的答案是正確的,如果它解決您的問題 – Vladimir 2010-01-08 09:56:36
作爲jdeprez說你不應該比較浮點值。比較浮點值是危險且不好的做法。相反,使用相當大的區域作爲謂詞,然後計算從距離返回對象數組中最近的點到距離搜索點的距離。 – Christopher 2012-07-16 23:53:39
您節省了我的一天..... :-) – 2016-12-28 07:24:06