尝试将非属性列表对象设置为NSUserDefault
Attempt to set a non-property-list object ( "<BC_Person: 0x8f3c140>" ) as an NSUserDefaults value for key personDataArray
Person
NSCoding
- (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:self.personsName forKey:@"BCPersonsName"]; [coder encodeObject:self.personsBills forKey:@"BCPersonsBillsArray"];}- (id)initWithCoder:(NSCoder *)coder { self = [super init]; if (self) { self.personsName = [coder decodeObjectForKey:@"BCPersonsName"]; self.personsBills = [coder decodeObjectForKey:@"BCPersonsBillsArray"]; } return self;}
NSString
BC_PersonClass
DataSave
BC_PersonClass
DataSave
- (void)savePersonArrayData:(BC_Person *)personObject{ // NSLog(@"name of the person %@", personObject.personsName); [mutableDataArray addObject:personObject]; // set the temp array to the mutableData array tempMuteArray = [NSMutableArray arrayWithArray:mutableDataArray]; // save the person object as nsData NSData *personEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:personObject]; // first add the person object to the mutable array [tempMuteArray addObject:personEncodedObject]; // NSLog(@"Objects in the array %lu", (unsigned long)mutableDataArray.count); // now we set that data array to the mutable array for saving dataArray = [[NSArray alloc] initWithArray:mutableDataArray]; //dataArray = [NSArray arrayWithArray:mutableDataArray]; // save the object to NS User Defaults NSUserDefaults *userData = [NSUserDefaults standardUserDefaults]; [userData setObject:dataArray forKey:@"personDataArray"]; [userData synchronize];}
蓝山帝景
慕少森
慕沐林林