1 //保存:
2 NSMutableArray* array = [[NSMutableArray alloc] init];
3 for(int i=0; i<3; i++){
4 MyObject *testObj = [[MyObject alloc] init];
5 testObj.lowValue =[NSNumber numberWithFloat:122.2+i ];
6 testObj.highValue = [NSNumber numberWithFloat:19888+i ];
7 testObj.titleString = [NSString stringWithFormat:@"BAOYU%d", i];
8 [array addObject:testObj];
9 }
10
11 [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:array] forKey:@"myarray"];
12
13 //读取:
14 NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:@"myarray"];
15 NSArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
16
17 for(MyObject *obj in oldSavedArray) {
18 NSLog(@"%f, %f, %@", [obj.lowValue floatValue], [obj.highValue floatValue], obj.titleString);
19 }