0

私のアプリには、カスタム クラス ファイルがあります。

使用してみ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
4

2 に答える 2

0

それを試してみてください....

[[NSUserDefaults standardUserDefaults]setValue:@"myValue" forKey:@"myKey"];//set value

NSString *myValue = [[NSUserDefaults standardUserDefaults]valueForKey:@"myKey"];//retrive value 
NSLog(@"%@",myValue);
于 2013-04-05T05:46:27.250 に答える