Our DNA is written in Swift

NSLog crashes with certain NSURLs

This is a bug in NSURL which managed to astonish me. Even as a seasoned developer you can only but marvel at the easy way to reproduce it and wonder what might be the reason for it happening.

A client reported that our app was crashing. When I launched the app in debugger I expected to see the exception to be something obvious, like a nil being unwrapped. But it turns out that there is a bug in NSLog. Filed as Radar rdar://24406969 and on Open Radar.


Some NSURLs are able to crash an app with EXC_BAD_ACCESS.

Steps to Reproduce

Add the following two lines to a new empty iOS app.

let URL = NSURL(string: "")
NSLog("Loading page with URL: \(URL)")

Run and weep.

Expected Results

The URL should be logged.

Actual Results

The app crashes with EXC_BAD_ACCESS as shown in the attached screen shot


This is the kind of crash that both delights and amuses. šŸ˜‰

NSLog Crash

Note: As a workaround I triedĀ absoluteString, but this also causes the crash to occur. Logging scheme, host and path individually seem to work. But better to remove the logging of NSURLs for the time being.

Categories: Bug Reports


  1. Update: Apparently the reason was that the URL contains % characters which are the indicator of placeholders on the first parameter of NSLog. DOH. (thanks Joshua May for pointing this out)

  2. How do we interpret that, then? It’s not really an NSLog bug, but there’s also no way to escape out the ‘%’ characters?

  3. That’s not a bug in NSLog. The way you are calling NSLog is wrong. Try NSLog(“Loading page with URL: %@”, URL)

  4. Your example works for me as of now, but have you tried this one:

    let url = NSURL(fileURLWithPath: “”)
    print(“url = \(url)”)

    Crashes with the same EXC_BAD_ACCESS šŸ˜¢ In this case it seems to be, that url is nil but not an optional. However this could be possible…