I use an NSURLConnection to download a file and when the user taps back I don't necessarily know if the connection is finished and has been properly disposed. So I added the following check where if the connection is not null, cancel it.
if (self.urlConnection){
[self.urlConnection cancel];
}
This worked in iOS 7/8 and I never once received an exception. But now in iOS 9 when I do the check to see if the connection exists (and it doesn't) I get an exception. This is the first line above, before I have actually made a call to the url.
I don't understand why checking to see if an object is nil would ever throw an exception and if it does - how can I be expected to guard against this exception.
Is there a new way to make sure an object exists and hasn't been released before I make a call to it?
Edit: This is how the property is declared:
@property (nonatomic, assign) NSURLConnection *urlConnection;
If the object hasn't actually been instantiated yet, the check works fine. It's only when the connection finishes and becomes nil and then I try to check if it is nil that the check explodes. This wasn't happening on earlier iOS versions.