tags:

views:

827

answers:

2

This is what the plist looks like as source code:

{
 authorLastName = Doe;
 authorFirstName = Jane;
 imageFilePath = "NoImage.png";
 title = "Account Test 1";
 year = 2009;
},
{
 authorLastName = Doe;
 authorFirstName = John;
 imageFilePath = "NoImage.png";
 title = "Account Test 2";
 year = 2009;
},

How come it isnt in XML format???

I want to count the total items of a plist, and display them like: '4 Accounts'.

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

NSArray *array = [[plistDict objectForKey:0]
                      sortedArrayUsingSelector:@selector(compare:)]; 

return([NSString stringWithFormat:@"%d Accounts", [array count]]);

However, the result returns 0. I want it to return the ammount of items in the dictionary.

A: 

Your return statement is relaying the number of items in the first element of the dictionary, not the number of items of the dictionary itself. Instead what I think what you want is something like:

return [NSString stringWithFormat:@"%d Accounts", [plistDict count]];
fbrereto
A: 

What about [plistDict count]? Since you're passing in 0 as the key to the dictionary you won't get anything back since you can't use nil as a key or a value.

Amuck