存儲MKMapItem
,我是能夠通過查看編譯器警告解決時,我遇到了一個問題,但我不明白爲什麼我能解決這個問題,或者如果我使用「最佳做法「。CLLocationCoordinates
我有一個對象模型,它將MKMapItem
中的經度和緯度座標分別存儲爲double
,存儲在NSManagedObject
中。當我去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;
這是讓編譯器高興還是有更好方法的最好方法?
您的解決方案是完全合理和有效的。真的,沒有必要改變它或擔心你做錯了什麼,這是一個很好的解決方案。 – 2015-03-13 20:50:37