tags:

views:

73

answers:

2
NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *myPlistPath = [documentsDirectory stringByAppendingPathComponent:@"Accounts.plist"];

NSArray  *arr = [NSArray arrayWithContentsOfFile:myPlistPath];

int count = 0; 
for (NSDictionary *dict in arr) { 
      count += dict.count; 
}

return count;

What am I doing wrong?

I get the following error with the above code: Program received signal: “EXC_BAD_ACCESS”.

+3  A: 

EXC_BAD_ACCESS is usually a memory fault, possibly caused by a bad address.

Start by printing out paths, documentsDirectory, myPListPath and arr (the addresses, not the contents) immediately after you set them, to see if any of them have been set to NULL.

paxdiablo
A: 

Try printing out myPListPath and verifying that the file it's referring to actually exists and is the correct format. If you ask me, chances are that on this line:

NSArray  *arr = [NSArray arrayWithContentsOfFile:myPlistPath];

something is going wrong, and arr is getting set to null.

Fritz H