在我的應用程序中,我有自定義類文件。如何使用iphone SDK中的NSUser默認值傳遞自定義類對象?
我嘗試使用但它表明我null
價值&也給錯誤控制檯類似
[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '<FSVenue: 0x181898c0>' of class 'FSVenue'. Note that dictionaries and arrays in property lists must also contain only property values.
我怎麼能自定義類的對象傳遞給另一個看法?
代碼自定義類是如下:
FSVenue.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface FSLocation : NSObject{
CLLocationCoordinate2D _coordinate;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic,strong)NSNumber*distance;
@property (nonatomic,strong)NSString*address;
@end
@interface FSVenue : NSObject<MKAnnotation>
@property (nonatomic,strong)NSString*name;
@property (nonatomic,strong)NSString*venueId;
@property (nonatomic,strong)FSLocation*location;
@end
FSVenue.m
#import "FSVenue.h"
@implementation FSLocation
@end
@implementation FSVenue
- (id)init
{
self = [super init];
if (self) {
self.location = [[FSLocation alloc]init];
}
return self;
}
-(CLLocationCoordinate2D)coordinate{
return self.location.coordinate;
}
-(NSString*)title{
return self.name;
}
@end
您已經嘗試了什麼? – Balu 2013-04-05 05:28:58
你能更清楚些嗎?任何關於你如何做userDefaults的代碼。 – satheeshwaran 2013-04-05 05:30:29
我附上Apple Developer文檔鏈接如下: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DrawColor/Tasks/StoringNSColorInDefaults.html#//apple_ref/doc/uid/20001693 http ://stackoverflow.com/questions/3000220/best-way-to-save-to-nsuserdefaults-for-custom-class – 2013-04-05 05:33:08