gpt4 book ai didi

ios - 在 nsarray of nsdictionaries 中搜索性能内存优化方式

转载 作者:行者123 更新时间:2023-11-29 02:49:53 26 4
gpt4 key购买 nike

这个问题是基于性能的,我得到了想要的结果。我有一系列这样的字典:

Printing description of arrAppointmentDictionary:
<__NSArrayM 0x16f962a0>(
{
"component_id" = 159;
total = 1;
},
{
"component_id" = 165;
total = 1;
},
{
"component_id" = 177;
total = 1;
},
{
"component_id" = 191;
total = 1;
},
{
"component_id" = 193;
total = 1;
}
)

我根据这样的键在字典中搜索:

for (int i = 0; i<arrAppointmentDictionary.count; i++)
{
NSMutableDictionary *appointmentDictionary = [arrAppointmentDictionary objectAtIndex:i];
NSArray *keys = [appointmentDictionary allKeys];
for (NSString *key in keys)
{
@autoreleasepool {
NSLog(@"Key is %@", key);
if([[appointmentDictionary objectForKey: key] isEqualToString:[rs stringForColumn:@"id"]])
{
layout.numberOfAppointments = [appointmentDictionary objectForKey: @"total"];
NSLog(@"number of appointments are >>>>>>>>>>>>>>>>> %@", [appointmentDictionary objectForKey: @"total"]);
}
}
}
}

我得到的结果是准确的。当从另一个 while 循环调用此 for 循环时,如何提高该 for 循环的性能/内存优化。

谢谢和问候。

最佳答案

这是一种方法:

NSString *wantedId = [rs stringForColumn:@"id"];
for (NSMutableDictionary *appointmentDictionary in arrAppointmentDictionary) {
if ([appointmentDictionary[@"id"] isEqualToString:wantedId]) {
layout.numberOfAppointments = appointmentDictionary[@"total"];
NSLog(@"number of appointments are >>>>>>>>>>>>>>>>> %@", appointmentDictionary[@"total"]);
break;
}
}

关于ios - 在 nsarray of nsdictionaries 中搜索性能内存优化方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24695451/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com