3 Replies
      Latest reply on Jan 2, 2020 1:17 AM by eskimo
      yogur Level 1 Level 1 (0 points)

        It is just report a problem and solution when I make a new single view app project on XCode11 with disabling ARC.

         

        Problem:

        First, I make a new project as Single View App on XCode11 with disabling ARC. And then I build and run it, the app is crashed.

         

        About Error:

        XCode11 makes a default "main.m" like below.

        The error will be occured in "return UIApplicationMain(argc, argv, nil, appDelegateClassName);" line.

         

        int main(int argc, char * argv[]) {

          NSString * appDelegateClassName;

          @autoreleasepool {

             // Setup code that might create autoreleased objects goes here.

             appDelegateClassName = NSStringFromClass([AppDelegate class]);

          }

          return UIApplicationMain(argc, argv, nil, appDelegateClassName);     // Error Occured.

        }

         

         

        Solution:

        I could resolve the problem when I put the "main.m" that made by XCode10, instead of XCode11.

         

        int main(int argc, char * argv[]) {

          @autoreleasepool {

             return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

          }

        }

         

        I'm not sure why Apple put the return code out of @autoreleasepoo {}.

         

         

        And also we need to set UIWindow property like below when we don't use SwiftUI.

         

        @interface AppDelegate : UIResponder <UIApplicationDelegate>

        @property (nonatomic, strong) UIWindow *window;

        @end

        • Re: Single view app project made on XCode 11 is crashed when ARC is disabled.
          eskimo Apple Staff Apple Staff (12,705 points)

          Personally, I don’t consider this to be a bug.  The built-in templates create ARC-enabled apps.  If you disable ARC on a file, or an entire project, it’s your responsibility to audit the affected code to make sure it’s compatible with MRR.

          Taking a step back, IMO you should not disable ARC for your entire project.  There are good reasons for why you might want to disable ARC for some focused subset of your code — for example, if you’re bringing in old code that’s not ARC compatible, or ARC is causing a performance problem in some tight loop — but the vast bulk of your app should have ARC enabled because it’s by far the safest option.

          Share and Enjoy

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

          ps DTS is closed 21 Dec through 1 Jan.

          • Re: Single view app project made on XCode 11 is crashed when ARC is disabled.
            john daniel Level 4 Level 4 (520 points)

            Your problem is that you allocate "appDelegateClassName" and deallocate it inside the autorelease pool. That's what an autorelease pool does. Then, you try to use it. Since you are accessing deallocated memory, your app crashes.

             

            You have to be careful with Apple's code. Apple is in the business of selling new iPhones. They really don't care anything about your business at all. They will default to enabling the latest Apple technologies with no consideration of whether that is a good idea for your app or not. If you are using the provided templates, this means that ARC is enabled and that your app will only run on the latest version of iOS13.3 and nothing earlier. In general, if your completed source code bears any resemblance to Apple's original templates or example code, then you are doing it very wrong.

              • Re: Single view app project made on XCode 11 is crashed when ARC is disabled.
                eskimo Apple Staff Apple Staff (12,705 points)

                If you are using the provided templates, this means that ARC is enabled and that your app will only run on the latest version of iOS 13.3 and nothing earlier.

                Just to clarify, these two consequences are independent.  That is, the fact that ARC is enabled does not elevate the deployment target.  ARC is supported on all versions of iOS that Xcode can build for.

                Share and Enjoy

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

                ps DTS is closed 21 Dec through 1 Jan.