这是 plist 看起来像原始的样子:
{
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;
},
我想计算一个 plist 的总项目,并将它们显示为:'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]]);
但是,结果返回 0。我希望它返回字典中的项目数量。