を保存するときに問題が発生しましたが、コンパイラの警告を見て解決できましたが、なぜ解決できたのか、または「ベスト プラクティス」を利用したかどうかがMKMapItem
わかりません。
MKMapItem
からの緯度と経度の座標を のとして別々に格納するオブジェクト モデルがdouble
ありNSManagedObject
ます。my クラスに移動しEditor\Create NSManagedObject Subclass
て作成すると、ヘッダーは次のようになります。
@class LocationCategory;
@interface PointOfInterest : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * address;
// Xcode spat out NSNumber instead of the double specified in the model setup screen
@property (nonatomic, retain) NSNumber * latitude;
@property (nonatomic, retain) NSNumber * longitude;
@property (nonatomic, retain) NSString * note;
@property (nonatomic, retain) LocationCategory *locationCategory;
@end
オブジェクトを追加しようとするまではすべて問題ありませんでしたが、managedObjectContext
次の警告が表示されました。
Assigning to 'NSNumber *' from incompatible type 'CLLocationDegrees' (aka 'double')
これらの行で:
newPOI.latitude = self.item.placemark.location.coordinate.latitude;
newPOI.longitude = self.item.placemark.location.coordinate.longitude;
PointOfInterest : NSManagedObject
サブクラスを変更して修正しました:
@property (nonatomic) double latitude;
@property (nonatomic) double longitude;
これはコンパイラを満足させる最善の方法ですか、それとももっと良い方法がありますか?