Eric Boumendil Eric Boumendil - 6 months ago 42
Swift Question

Why SKProductsRequestDelegate/SKRequestDelegate didFailWithError throws EXC_BAD_ACCESS on NSError?

I use

SKProductsRequest
to download product infos from App Store.
When I test a connectivity loss on my device, the request fails, but my app crashes within the
SKRequestDelegate
when I try to
NSLog
the error:

crash

What am I doing wrong ? Another curious thing to me is that Expression Inspector is able to display
NSError.debugDescription
...

It fails on the first request, so there is no possible bug relative to multiple uses of productRequest variable (which is a strong ref in my swift class).

Answer

I finally found the reason. It is not related to SKProductsRequest!

I think there is a nasty bug with NSLogand string interpolation because when I replace:

NSLog("Failed: \(error.debugDescription)")

by

print("Failed: \(error.debugDescription)")

all is fine!

Apparently, the content of the error message can provoke a EXC_BAD_ADDRESS in NSLog (even without string interpolation in fact: NSLog(error.debugDescription) fails too).