I have a problem with this section of code:
Here is the getSavedChanges method:
Here is the pathInDocumentDirectory() function:
The problem that I am experiencing is that after my objects are unarchived and added to the NSArray, they are sent the message "count." This happens when I send "count" to the NSArray. I don't want the count of the objects IN the NSArray, I want the count of the NSArray itself... Why are the objects within the NSArray being sent "count"?
Just in case you were wondering, here is the code from the debugger where the exception is thrown. "MapPoint" is the name of the class of the unarchived objects:
Code:
NSArray *array = [[[NSArray alloc] init] autorelease];
array = [self getSavedChanges];
NSLog(@"%u", [array count]);
Here is the getSavedChanges method:
Code:
- (NSArray *)getSavedChanges
{
NSArray *array = [[[NSArray alloc] init] autorelease];
array = [NSKeyedUnarchiver unarchiveObjectWithFile:pathInDocumentDirectory(@"points.data")];
return array;
}
Here is the pathInDocumentDirectory() function:
Code:
NSString *pathInDocumentDirectory(NSString *filename)
{
NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [documentDirectories objectAtIndex:0];
return [documentDirectory stringByAppendingPathComponent:filename];
}
The problem that I am experiencing is that after my objects are unarchived and added to the NSArray, they are sent the message "count." This happens when I send "count" to the NSArray. I don't want the count of the objects IN the NSArray, I want the count of the NSArray itself... Why are the objects within the NSArray being sent "count"?
Just in case you were wondering, here is the code from the debugger where the exception is thrown. "MapPoint" is the name of the class of the unarchived objects:
Code:
2012-02-15 15:32:01.342 MyLocation[16596:11c03] -[MapPoint count]: unrecognized selector sent to instance 0x6d8d540
2012-02-15 15:32:01.362 MyLocation[16596:11c03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapPoint count]: unrecognized selector sent to instance 0x6d8d540'
*** First throw call stack:
(0x157d052 0x139dd0a 0x157eced 0x14e3f00 0x14e3ce2 0x2c53 0x23864e 0x198a73 0x198ce2 0x198ea8 0x19fd9a 0x170be6 0x1718a6 0x180743 0x1811f8 0x174aa9 0x1380fa9 0x15511c5 0x14b6022 0x14b490a 0x14b3db4 0x14b3ccb 0x1712a7 0x172a9b 0x1d02 0x1c75)
terminate called throwing an exception(gdb)