1

Okay I've made an array of NSNumber objects that I've stored into an NSMutableArray. When the game loads it's unarchived and retained but all the NSNumber objects are gone. Here's my code:

times = [[NSMutableArray alloc] initWithObjects:[[NSNumber alloc] initWithFloat:time],nil];
[NSKeyedArchiver archiveRootObject:times toFile:@"times"];
...

NSMutableArray *newTimes = [[NSKeyedUnarchiver unarchiveObjectWithFile:@"times"] retain];
times = [[NSMutableArray alloc] initWithArray:newTimes];
[newTimes release];

Please help.

  • Are you sure that the NSNumber objects are in the array before you archive it? Are yo sure that `newTimes` isn't nil? – kubi Jun 20 '10 at 20:16
  • Save the archive in XML Property List format. Then open it using the Property List Editor. Ensure that your numbers are there. If not, your problem is with archiving. If so, your problem is with unarchiving. – Gregory Higley Jun 20 '10 at 20:20
  • I do NSLog(@"%d",[newTimes count]); and it comes out right. but if I do NSLog(@"%f",[[newTimes objectAtIndex:0] floatValue]); it comes out as some ridiculous number like 536870912 or -536870912 (it's always some huge power of 2). – Dane Graphics Jun 20 '10 at 20:21
  • You don't need to archive an array if all its contents are plist objects. Just use `-writeToFile:…` and `+arrayWithContentsOfFile:`. – kennytm Jun 20 '10 at 20:28
  • What do I call arrayWithContentsOfFile on? – Dane Graphics Jun 20 '10 at 20:35
  • What if you do NSLog(@"%@",[newTimes objectAtIndex:0]); ? If you really have an instance of NSNumber in there, you should get just that number returned. If you have some other strange object, you may get some other useful information. If you have a garbage pointer, you will get a seg fault. – Jason Coco Jun 20 '10 at 20:36
  • Okay I did what KennyTM said. and what Jason Coco said. the NSLog returns the correct number but the NSNumbers still disappear right after the NSLog. – Dane Graphics Jun 20 '10 at 20:41

0 Answers0