在NSUserDefault中将自定义对象存储在NSMutableArray中
保留:
[prefs setObject:results forKey:@"lastResults"];[prefs synchronize];
NSData *data = [NSData dataWithBytes:&results length:sizeof(results)];[prefs setObject:data forKey:@"lastResults"];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:results];[prefs setObject:data forKey:@"lastResults"];
负载:
lastResults = (NSMutableArray *)[prefs objectForKey:@"lastResults"];
NSData *data = [prefs objectForKey:@"lastResults"];memcpy(&lastResults, data.bytes, data.length);
NSData *data = [prefs objectForKey:@"lastResults"];lastResults = [NSKeyedUnarchiver unarchiveObjectWithData:data];
#import "Location.h"@implementation Location@synthesize locationId;@synthesize companyName;@synthesize addressLine1;
@synthesize addressLine2;@synthesize city;@synthesize postcode;@synthesize telephoneNumber;@synthesize description;
@synthesize rating;@synthesize priceGuide;@synthesize latitude;@synthesize longitude;@synthesize userLatitude;
@synthesize userLongitude;@synthesize searchType;@synthesize searchId;
@synthesize distance;@synthesize applicationProviderId;@synthesize contentProviderId;- (id) initWithCoder: (NSCoder *)coder{
if (self = [super init])
{
self.locationId = [coder decodeObjectForKey:@"locationId"];
self.companyName = [coder decodeObjectForKey:@"companyName"];
self.addressLine1 = [coder decodeObjectForKey:@"addressLine1"];
self.addressLine2 = [coder decodeObjectForKey:@"addressLine2"];
self.city = [coder decodeObjectForKey:@"city"];
self.postcode = [coder decodeObjectForKey:@"postcode"];
self.telephoneNumber = [coder decodeObjectForKey:@"telephoneNumber"];
self.description = [coder decodeObjectForKey:@"description"];慕森王
叮当猫咪