我需要从我的NSOperation中设置一个字符串,但是如何知道操作是否已完成?因为它没有达到我设定的断点,或者我没有正确地调用我的NSOperation?如果是,我应该如何调用我的操作?
这是我的代码
- (void)operationDidFinish:(MJOperation *)operation
{
NSString *strng = [MJUtilities decodedStringFromXMLData:operation.receivedData];
mainString = [NSString stringWithFormat:mainString, strng];
}
现在我需要获取mainString的值
答案 0 :(得分:3)
在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
};