-1
在我的模態對象中有兩個值 我試圖存儲在NSUserDefaults中。這是我的代碼將NSobject數據存儲到Nsuserdefaults中
接口文件:
@interface collectionModel : NSObject <NSCoding> {
}
@property(nonatomic,retain) NSString *name;
@property(nonatomic,retain) NSString *author;
實現文件:
@implementation collectionModel
@synthesize name = _name;
@synthesize author = _author;
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super init]) {
self.name = [aDecoder decodeObjectForKey:@"name"];
self.author = [aDecoder decodeObjectForKey:@"author"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:_name forKey:@"name"];
[aCoder encodeObject:_author forKey:@"author"];
}
ViewController.M
#import "collectionModel.h"
parsedCollectionArr = [[NSMutableArray alloc] init];
for (NSDictionary *obj in collectionBalk) {
NSString * Name = [obj objectForKey:@"Name"];
NSString * author = [obj objectForKey:@"author"];
collectionModel *dataObj = [[collectionModel alloc] init];
dataObj.name = Name;
dataObj.author = author;
[parsedCollectionArr addObject:dataObj];
}
NSLog(@"parsedCollectionArr count ---->>>> %d",23);
這裏我想將這個parsedCollectionArr存儲在NSUserDefaults中並從它中取出。任何人都可以幫助我。
可能的複製[如何在NSUserDefaults中保存NSMutablearray](http://stackoverflow.com/questions/19634426/how-to-save-nsmutablearray-in-nsuserdefaults) –
另請參考http:// stackove rflow.com/questions/2315948/how-to-store-custom-objects-in-nsuserdefaults –
按照@Teja Nandamuri建議鏈接 –