NSDictionary计数

Luc*_*iga 7 objective-c ios

我怎么能算出"账单"里面有多少笔?

bills =     (
            {
        id = 1;
        name = "Cursus Nibh Venenatis";
        value = "875.24";
    },
            {
        id = 2;
        name = "Elit Fusce";
        value = "254.02";
    }
);
Run Code Online (Sandbox Code Playgroud)

我这样算:

NSUInteger keyCount = [resultsDictionary count];
NSLog(@"%i", keyCount);
Run Code Online (Sandbox Code Playgroud)

谢谢!

Hen*_*mak 6

一个天真的解决方案会假设OP想要计数bills,这恰好是一个数组,所以解决方案就是

NSLog(@"Count: %i", [[resultsDictionary objectForKey: @"bills"] count]);
Run Code Online (Sandbox Code Playgroud)

但是,如果您想要计算多个对象的字典,那么将它们全部枚举是唯一的方法.