gpt4 book ai didi

ios - 一起解析数组的每个元素 - iOS

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:21:43 25 4
gpt4 key购买 nike

我有一个数组,如下例所示:

[
{
"lx": 144,
"ly": 57,
"mx": 144,
"my": 56
},
{
"lx": 321,
"ly": -4,
"mx": 298,
"my": 16
}
]

我想给每个元素设置一半的值。

简而言之,我想要如下内容。

[
{
"lx": 72,
"ly": 28.5,
"mx": 72,
"my": 28
},
{
"lx": 160.5,
"ly": -2,
"mx": 149,
"my": 8
}
]

我正在使用以下代码:

    NSMutableArray * tempArray = [NSMutableArray arrayWithCapacity:0];
for (int i = 0; i < jsonArray.count; i++)
{
NSMutableDictionary * tempDict = [NSMutableDictionary dictionaryWithDictionary:(NSDictionary *)jsonArray[i]];
tempDict[@"lx"] = @([tempDict[@"lx"] intValue]/2);
tempDict[@"ly"] = @([tempDict[@"ly"] intValue]/2);
tempDict[@"mx"] = @([tempDict[@"mx"] intValue]/2);
tempDict[@"my"] = @([tempDict[@"my"] intValue]/2);
[tempArray addObject:tempDict];
}

我用一个循环完成了它,它在处理少量数据时工作正常。

但是当我有大量数据时,应用程序行为会变慢。

任何帮助将不胜感激

谢谢...

最佳答案

也许您可以在后台线程中异步计算它,这样您就不会阻塞 UI。

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// Code to execute in background thread
});

关于ios - 一起解析数组的每个元素 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25198074/

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