这个问题是基于表现的,我得到了理想的结果。 我有一系列这样的词典:
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循环时,如何提高性能/内存优化。
谢谢&amp;问候。
答案 0 :(得分:1)
以这种方式:
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;
}
}