我需要从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/

10-14 09:59