gpt4 book ai didi

ios - 从 NSBlockOperation 获取值(value)?

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

大家好,我很沮丧,因为我想改进代码,但我没有得到好的结果,这是我的代码

NSBlockOperation *blockOperation1 = [NSBlockOperation blockOperationWithBlock: ^{
value1 = [self getDiferences:0.0 finx:width iniy:0.0 finy:cuartoheith image:imagen1 imagetoComapare:imagen2];
}];
[queue addOperation:blockOperation1];

NSBlockOperation *blockOperation2 = [NSBlockOperation blockOperationWithBlock: ^{
value2 = [self getDiferences:0.0 finx:width iniy:0.0 finy:cuartoheith image:imagen1 imagetoComapare:imagen2];
}];
[queue addOperation:blockOperation2];

NSBlockOperation *blockOperation3 = [NSBlockOperation blockOperationWithBlock: ^{
value3 = [self getDiferences:0.0 finx:width iniy:0.0 finy:cuartoheith image:imagen1 imagetoComapare:imagen2];
}];
[queue addOperation:blockOperation3];

NSBlockOperation *blockOperation4 = [NSBlockOperation blockOperationWithBlock: ^{
value4 = [self getDiferences:0.0 finx:width iniy:0.0 finy:cuartoheith image:imagen1 imagetoComapare:imagen2];
}];
[queue addOperation:blockOperation4];

我想像这样在 NSBlockOperation 之外使用这个值 valuetotal=value1+value2+value3+value4;请帮助或提供更好的解决方案

最佳答案

添加另一个依赖于您的其他操作的操作(使用 addDependency:),并在那里添加您的代码。排队此操作。它将等待所有其他人完成,然后使用他们的输出。

例如,

NSBlockOperation *blockOperationFinal = [NSBlockOperation blockOperationWithBlock: ^{
valueTotal = value1 + value2 + value3 + value4;
}];

[blockOperationFinal addDependency:blockOperation1];
[blockOperationFinal addDependency:blockOperation2];
[blockOperationFinal addDependency:blockOperation3];
[blockOperationFinal addDependency:blockOperation4];

[queue addOperation:blockOperationFinal];

关于ios - 从 NSBlockOperation 获取值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20712829/

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