If you get a EXC_BAD_ACCESS
with an address of 0x0
, that generally means that a nil
value was used in a context where nil
is not permitted.
In this case, it is a result of the fact that your URL string is not valid. Spaces are not allowed. Thus your resulting URL
variable is nil
, which will result in the behavior you describe. You probably want to percent escape the URL string, e.g.:
NSString *URLString = @"http://tesg.com.au/portal/media/reports/1367365180_367 Collins Passive April 2013.pdf";
NSURL *URL = [NSURL URLWithString:[URLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
To identify this sort of exception in the future, you can use exception breakpoints, which will often help identify the offending line of code. Or just carefully review your code code for situations where you may have unintentionally passed a nil
value to a method that does not accept it.
If, however, you ever get a EXC_BAD_ACCESS
with a value other than 0x0
, that is often a result of an attempt to use a previously deallocated object. (Not always, but frequently. Fortunately, ARC has made this sort of problem less common.) Clearly, this is not the case here, but you asked how one would identify a situation where you attempt to use a previously deallocated object.
To diagnose that situation, you would generally turn on "zombies" (see Running Your Application with Diagnostics). By the way, once you finish your diagnostics with zombies, make sure you turn them back off, as you don't want to keep zombies turned on (especially in a production app).
Anyway, in this case, because the address was 0x0
, it wasn't a result of a deallocated object, but rather the problem was the incorrect usage of a nil
value, caused by the invalid URL.