What is a secure way to verify protocol response

Here's the script:

The view controller pushes the new controller towards the nav controller. This child controller creates a model that uses NSURLConnection. When this connection ends, it will make a call like this:

[self.delegate modelDidFinishParsing:self];

      

What's the safest way to generate this code? Right now I have this code and it crashes in a certain situation:

if ([self.delegate conformsToProtocol:@protocol(ModelDelegate)]) [self.delegate modelDidFinishParsing:self];

      

The situation when it crashes is when the view controller that owns the model is popped off the stack before the model completes. Should I make the ivar model so that the controller will release it into its own - (void)dealloc

?

+2


a source to share


1 answer


In your check, you can make sure that the delegate is not nil



if (self.delegate && [self.delegate conformsToProtocol...]) [self.delegate modelDidFinishParsing:self];

      

+1


a source







All Articles