ios - 根据键的值从字典的 NSArray 中获取常用元素
<p><p>我有 NSDictionaries 的 NSMutableArray。这是数组。</p>
<pre><code>Month records (
{
BMI = "209.75";
Date = "15/07/2014 09:03 AM";
Height = 42;
Weight = 37;
day = 15;
month = 7;
year = 2014;
},
{
BMI = "366.67";
Date = "21/07/2014 09:03 AM";
Height = 30;
Weight = 33;
day = 21;
month = 7;
year = 2014;
},
{
BMI = "831.02";
Date = "15/07/2014 09:04 AM";
Height = 19;
Weight = 30;
day = 15;
month = 7;
year = 2014;
}
)
</code></pre>
<p>现在我想获取相同“day”的元素(根据这里,“day=15”有 2 个元素,“day=7”有 1 个元素)。然后计算该特定日期的平均 BMI 值。</p>
<p>一般来说,我的要求是获取公共(public)元素(基于键的值)并将它们放入一个新数组中。使用大型数据集在运行时执行此操作的最佳方法是什么。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><pre><code>int day = /* ... */;
NSArray* recordsForDay = ];
</code></pre>
<p>或:</p>
<pre><code>NSIndexSet* indexes = [record indexesOfObjectsPassingTest:^BOOL (NSDictionar* record, NSUInteger idx, BOOL *stop) {
return [ intValue] == day;
}];
NSArray* recordsForDay = ;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 根据键的值从字典的 NSArray 中获取常用元素,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25195844/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25195844/
</a>
</p>
页:
[1]