属性列表中的记录总数 [英] Sum of records in property list

查看:78
本文介绍了属性列表中的记录总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算键的所有字典中所有数字的总和,例如小时"?

How can I calculate the sum of all numbers in all dictionaries for the key for example "Hours"?

找不到有关此的任何信息.

Couldn't find any informations about that.

这是我正在谈论的财产清单中的一部分:

Here is piece of my property list I'm talking about:

<plist version="1.0">
<array>
    <dict>
        <key>Address1</key>
        <string>17 Stanley Road</string>
        <key>Address2</key>
        <string>Essex</string>
        <key>City</key>
        <string>Southend On Sea</string>
        <key>Email</key>
        <string>lmozdzen@gmail.com</string>
        <key>Lessons</key>
        <array>
            <dict>
                <key>LessonComment</key>
                <string></string>
                <key>LessonDate</key>
                <string>05/06/2013</string>
                <key>LessonHomework</key>
                <string></string>
                <key>LessonHours</key>
                <integer>1</integer>
                <key>LessonNext</key>
                <string></string>
                <key>LessonNumber</key>
                <string>1</string>
                <key>LessonTime</key>
                <string></string>
            </dict>
            <dict>
                <key>LessonComment</key>
                <string>Ryun</string>
                <key>LessonDate</key>
                <string></string>
                <key>LessonHomework</key>
                <string>T</string>
                <key>LessonHours</key>
                <integer>2</integer>
                <key>LessonNext</key>
                <string>Ty</string>
                <key>LessonNumber</key>
                <string>4</string>
                <key>LessonTime</key>
                <string></string>
            </dict>
        </array>

我想要键"LessonHours"的所有数字的总和

I want the sum of all numbers for key "LessonHours"

推荐答案

使用

或者您可以通过循环使用平面旧样式添加.

Or you can use plane old style addition using loop.

NSInteger sum=0;
for(NSString *string in yourDict){
    sum+=[string integerValue];
}

这篇关于属性列表中的记录总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆