I have a plist written from a NSMutableArray by [NSMutableArray writeToFile]. When trying to load that same plist with the following code:
NSArray *testArray = [NSArray arrayWithContentsOfFile:[self pathForDataFile:@"reportingSpeicher.plist"]];
NSLog(@"count = %@",[testArray count]);
I get bad access on the count or on any other operation I try on testArray. BUT:
NSLog(@"testArray = %@", testArray);
correctly returns:
testArray = (
{
benutzername = "t.h";
datum = "2010-07-15";
dauerInStunden = 1;
phasenName = "Projektsteuerung,32开发者_StackOverflow社区";
projektName = "projekt AG,23";
soapSpeicher = {
PasswortAsMD5 = someMD5sum;
benutzername = "t.h";
datum = "2010-07-15";
dauerInStunden = 1;
phasenid = 32;
projektid = 23;
taetigkeit = whateveryoudid;
};
taetigkeit = whateveryoudid;
} )
I'm guessing there is either some basic memory management involved or the type returned is somehow corrupted/not an NSArray. Those three lines should really be simple enough - I just can't get it to work. I'd appreciate any help!
You need to initialise the array first. Use NSArray *testArray = [[NSArray alloc] initWithContentsOfFile:[self pathForDataFile:@"reportingSpeicher.plist"]];
.
Your NSLog statement is incorrect. The %@ format string is used when printing out an Objective-C object, but [testArray count] returns a plain int, and when NSLog tries to send the result a -description
message to print it out, that results in a crash. You'll want to use %d instead to print out the integer value.
NSLog(@"count = %d",[testArray count]);
精彩评论