在我的应用程序中,我有自定义类文件。
我尝试使用ObjectforKey
,但它向我显示了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