gpt4 book ai didi

objective-c - 快速连续发出多个请求时,RestKit崩溃

转载 作者:行者123 更新时间:2023-12-01 19:18:10 25 4
gpt4 key购买 nike

我有一个带有两个按钮的按钮,它们开始使用RestKit从Web服务器下载一些数据。

现在,如果用户快速连续两次点击两个按钮,我的应用程序将崩溃并在下面生成崩溃日志。

我这样发起请求:

-(void)loadDataAtPath:(NSString *)path completion:(ResultArrayBlock)completionBlock failed:(ResultFailedBlock)failedBlock
{
RKObjectMapping *groupMapping = [Group mapping];

[self.objectManager.mappingProvider setMapping:groupMapping forKeyPath:@"groups.group"];
[self.objectManager.mappingProvider setObjectMapping:groupMapping forKeyPath:path];

[self.objectManager loadObjectsAtResourcePath:path usingBlock:^(RKObjectLoader *loader) {
loader.onDidLoadObjects = ^(NSArray *array){

// Do the reverse mapping of the group
for (Group *c in array) {
for(Person *p in c.persons){
p.group = c;
}
}

completionBlock(array);

};
loader.onDidFailWithError = failedBlock;
}];
}

我首先以为问题是for循环,我在其中进行了数据的映射后设置,但是即使在注释for循环时,问题仍然存在。

奇怪的是,即使我打开 Network Link Conditioner,模拟器中也不会出现此问题.prefpane

碰撞

当我在设备上调试时,会在控制台上看到以下内容。
[PLCrashReport] Terminated stack walking early: Corrupted frame
[PLCrashReport] Terminated stack walking early: Corrupted frame

崩溃日志如下所示:
Application Specific Information:
*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSCFDictionary: 0x3c14a0> was mutated while being enumerated.'

Last Exception Backtrace:
0 CoreFoundation 0x3734e88f __exceptionPreprocess + 162
1 libobjc.A.dylib 0x35053259 objc_exception_throw + 32
2 CoreFoundation 0x3734e3b3 __NSFastEnumerationMutationHandler + 162
3 MyApp 0x0008f5bf -[RKObjectMapper performKeyPathMappingUsingMappingDictionary:] + 407
4 MyApp 0x0008fa45 -[RKObjectMapper performMapping] + 673
5 MyApp 0x0008ac7d -[RKObjectLoader mapResponseWithMappingProvider:toObject:inContext:error:] + 1045
6 MyApp 0x0008b04f -[RKObjectLoader performMapping:] + 575
7 MyApp 0x0008b22b __47-[RKObjectLoader performMappingInDispatchQueue]_block_invoke_0 + 247
8 libdispatch.dylib 0x3046ec59 _dispatch_call_block_and_release + 12
9 libdispatch.dylib 0x30479cab _dispatch_queue_drain + 274
10 libdispatch.dylib 0x30479b19 _dispatch_queue_invoke$VARIANT$up + 36
11 libdispatch.dylib 0x3047a78b _dispatch_worker_thread2 + 214
12 libsystem_c.dylib 0x33bbddfb _pthread_wqthread + 294
13 libsystem_c.dylib 0x33bbdcd0 start_wqthread + 8

最佳答案

正如@PhillipMills所建议的那样,当您查看performKeyPathMappingUsingMappingDictionary时,您可以轻松地看到答案。您的问题是使用这些行反复设置映射:

[self.objectManager.mappingProvider setMapping:groupMapping forKeyPath:@"groups.group"];
[self.objectManager.mappingProvider setObjectMapping:groupMapping forKeyPath:path];

如果在映射响应时调用此行,则会触发错误,因为您正在更改试图快速枚举的同一词典。

通常,您将在初始配置中的某个位置设置映射,而不是每次都这样设置。

关于objective-c - 快速连续发出多个请求时,RestKit崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11700055/

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