7 Replies
      Latest reply on Oct 1, 2017 2:02 PM by PBK
      tbacardit Level 1 Level 1 (0 points)

        I'm doing maintenance for a pretty old app dating back to iOS 7-8, however when my coworker was debuging it in his iOS device using iOS10 it crashes whenever a NSLog is sent a nil value NSString.

        • Re: NSLog crashes when sent a nil value inside a ios 10.0.2 enviroment
          eskimo Apple Staff Apple Staff (13,395 points)

          I was unable to reproduce the problem here in my office.  Here’s what I did:

          1. On 10.11.6 using Xcode 8, I created a new test project from the Single View Application template.

          2. I changed -application:didFinishLaunchingWithOptions: as shown below.

            Note This somewhat convoluted code ensures that the compiled doesn’t do any clever optimisations; it can’t know that str will be nil.

          3. I ran it, both from Xcode and from the home screen.

          In both cases it successfully logged the nil:

          2016-10-12 11:41:18.282551 xxos[972:565782] QQQ (null)

          I’m not sure what’s going on in your app but I’m pretty sure that the issue is not as simple as a bug in NSLog’s handling of nil.

          Perhaps you can post a snippet of code that reproduces the problem?  Or a crash log?

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

          - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
              // Override point for customization after application launch.
              NSData * data = [NSData dataWithBytes:"\x80" length:1];
              NSString * str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
              NSLog(@"QQQ %@", str);
              return YES;