gpt4 book ai didi

ios - 从主线程上的委托(delegate)方法接收答案

转载 作者:行者123 更新时间:2023-11-29 00:44:40 26 4
gpt4 key购买 nike

我有以下场景:我想在后台线程上多次调用一个方法,但返回值来自委托(delegate)方法,我认为该方法是在主线程上调用的。我如何在后台线程上处理这个问题?

NSOperationQueue *operationQueue = [NSOperationQueue new];
for (int i = 0 ; i < 100; i++) {
NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:^{
[self.routingService calculateRoute:self.routeSettings];
}];
[self.operationQueue addOperation:blockOperation];
}

//Delegate method
- (void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformation *)routeInformation {

//Here I want to process routeInformation
}

请帮帮我。 :)

最佳答案

您可以在委托(delegate)方法中执行此操作

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//add your processing code here
});

关于ios - 从主线程上的委托(delegate)方法接收答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38786058/

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