drbj
drbj

Reputation: 115

How to know if NSOperation operation is finished?

I need to set a string from my NSOperation, but how can I know if the operation is finished? Cause it is not hitting the breakpoint that I've set, or I am not calling my NSOperation properly? If yes, how should I call my operation?

Here's my code

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

mainString = [NSString stringWithFormat:mainString, strng];

}

Now I need to get the value of mainString

Upvotes: 1

Views: 344

Answers (1)

stevekohls
stevekohls

Reputation: 2255

Set the completionBlock property on your NSOperation. When the operation finishes, the completionBlock is called.

See the NSOperation documentation for more info: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSOperation_class/#//apple_ref/occ/instp/NSOperation/completionBlock

Try something like this:

__block NSString *mainString;

...

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

Upvotes: 3

Related Questions