gpt4 book ai didi

ios - 如何知道NSOperation操作是否完成?

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

我需要从NSOperation中设置一个字符串,但是如何知道操作是否完成?是因为它没有达到我设置的断点,还是没有正确调用NSOperation?如果是,我该怎么称呼我的手术?

这是我的代码

- (void)operationDidFinish:(MJOperation *)operation
{
NSString *strng = [MJUtilities decodedStringFromXMLData:operation.receivedData];

mainString = [NSString stringWithFormat:mainString, strng];

}

现在我需要获取mainString的值

最佳答案

completionBlock上设置NSOperation属性。操作完成后,将调用completionBlock

有关更多信息,请参见NSOperation文档:https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSOperation_class/#//apple_ref/occ/instp/NSOperation/completionBlock

尝试这样的事情:

__block NSString *mainString;

...

myOperation.completionBlock = ^{
NSString *strng = [MJUtilities decodedStringFromXMLData:myOperation.receivedData];
mainString = [NSString stringWithFormat:mainString, strng];
// here you should do something with mainString
};

关于ios - 如何知道NSOperation操作是否完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37871332/

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