Occasional Crash Setting UILabel Text – NSString substringWithRange

I have noticed a few crash reports from the App store recently. However, I can’t recreate the error using the simulator or on my iPhone 5.

The App crashes when the user tries to display a list of recordings. The line which fails is where the UILabel text “recordingName.text” is set to a substring of the filename string.

The filename string would typically be something like this:

VoCo_DATE_2015-05-14 16:14:55_NAME_Arpeggio #02

The substring should in this case result in this:

Arpeggio #02

Here is the section of code:

UILabel *recordingName = (UILabel *)[cell viewWithTag:100];
NSRange rangeNameTag = [fileNameWithoutExt rangeOfString:@"_NAME_"];
NSRange rangeOfRecordingName = NSMakeRange(rangeNameTag.location+6, fileNameWithoutExt.length-6-rangeNameTag.location);
recordingName.text = [fileNameWithoutExt substringWithRange: rangeOfRecordingName];

Here’s the exception I get from the App store crash log.

Last Exception Backtrace

One of the app users emailed me and said that it fails consistently for them.


Source: ios

Leave a Reply