小编Joh*_*röm的帖子

在对象内部使用NSString进行NSCoding

我的问题是我检索我的NSArray Store对象,我的所有NSString属性都导致BadAccess错误.int和double属性工作正常!

store.h

@interface Store : NSObject<NSCoding> {
    NSString *Name;
    NSString *Address;
    NSString *Phone;
    double GeoLong;
    double GeoLat;
    int ID;         
}

@property (nonatomic, retain) NSString *Name;
@property (nonatomic, retain) NSString *Address;
@property (nonatomic, retain) NSString *Phone;
@property (nonatomic) double GeoLat;
@property (nonatomic) double GeoLong;
@property (nonatomic) int ID;

@end
Run Code Online (Sandbox Code Playgroud)

store.m

@implementation Store

@synthesize Name;
@synthesize ID;
@synthesize Address;
@synthesize Phone;
@synthesize GeoLat;
@synthesize GeoLong;


/** Implentation of the NSCoding protocol. */

-(void)encodeWithCoder:(NSCoder *)encoder
{
    [encoder encodeInt:ID forKey:@"ID"]; …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsuserdefaults nscoding nskeyedarchiver

7
推荐指数
1
解决办法
5032
查看次数