1 Reply
      Latest reply on Oct 22, 2019 10:04 AM by junkpile
      patrickkidd Level 1 Level 1 (0 points)

        I am getting crashes on very simple object access after upgrading to iOS 13. See examples below. I wonder if there is some change to the language or to default settings in Xcode causing these? Or maybe there is something fundamental that I don't understand about how properties are managed? This code has been reliable for a few iOS versions until now.

         

        EXAMPLE 1: The following snipped crashes when printing _iCloudRoot:

         

                _iCloudRoot = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
                if (_iCloudRoot != nil) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        NSLog(@"iCloud available at: %@", _iCloudRoot);
                        completion(TRUE);
                    });
                }
        

         

        Here is the property declaration:

         

        @property(nonatomic, strong) NSURL * iCloudRoot;

         

        EXAMPLE 2: The following snippet crashes when accessing calling NSURL.path on an object returned through the two member methods

         

        - (NSURL *)localRoot {
            if (_localRoot == nil) {
                NSArray * paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
                _localRoot = [paths objectAtIndex:0];
            }
            return _localRoot;
        }
        
        - (NSURL *) documentsFolderPath {
            if(_forcedDocRoot) {
                return _forcedDocRoot;
            } else if (self.iCloudAvailable && self.iCloudOn) {
                return [self.iCloudRoot URLByAppendingPathComponent:@"Documents" isDirectory:YES];
            } else {
                return self.localRoot;
            }
        
        }
        
        - (void)loadLocal {
            
            // this crashes on [docRoot path] below...
            NSURL *docRoot = [self documentsFolderPath];
            if(!docRoot) {
                NSLog(@"no doc root!");
                return;
            }
        
            // this prevents the crash on [docRoot path] below...
            // NSArray * paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
            // NSURL *docRoot = [paths objectAtIndex:0];
            
            NSString* filePath = [docRoot path];
        

        Here is the property declaration:

         

        - (NSURL *) documentsFolderPath;
        @property(nonatomic, strong) NSURL * localRoot;

         

        Thanks!

        • Re: Crashes in basic property access after iOS 13?
          junkpile Level 6 Level 6 (2,485 points)

          Just to be clear, you're not accessing the property; you're bypassing the property and accessing the backing instance variable directly. Myself I don't do that. I almost always use the property syntax.

           

          Anyway. "It crashes" is not sufficient information to diagnose. What is the error message printed to the console when it crashes?