1

を保存するときに問題が発生しましたが、コンパイラの警告を見て解決できましたが、なぜ解決できたのか、または「ベスト プラクティス」を利用したかどうかが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;

これはコンパイラを満足させる最善の方法ですか、それとももっと良い方法がありますか?

4

1 に答える 1