6 Replies
      Latest reply on Mar 26, 2020 11:12 AM by JoshyMW
      xianritchie Level 1 Level 1 (0 points)

        I am running Catalina (10.15) with XCode11. After creating a new project and selecting the option to Use SwiftUI, the file opens, but i get an error message in the preview window;

         

        'Cannot preview in this file -- active scheme does not build this file. '

         

        the info button says 'Select a scheme that builds a target which contains the current file, or add this file to a target that is built by the current scheme.'

         

        i've tried opening numerous new projects, with and without unit tests, but none of them allow it to be previewed. I did see on Twitter that I'm not alone in seeing this issue. Any ideas on steps to troubleshoot it?

         

        Thanks all.

        • Re: Cannot preview SwiftUI
          xianritchie Level 1 Level 1 (0 points)

          I figured out the issue. As an update, i've tried a couple of suggestions from Twitter:

           

          - unselecting the unit test options when creating the project.

          - running

          sudo xcodebuild -license

          and going through the license agreement

           

          Created a new project, and it wa still not allowing a preview.  Then I realized that my Documents folder is actually being stored in iCloud Drive. I went back to my root user directory on my local HD and created a new folder in my user folder for the project, and after creating it, it worked without issue.

          • Re: Cannot preview SwiftUI
            CoffeeTree Level 1 Level 1 (0 points)

            What worked for me is I went to file inspector in the utilities area on the right hand side of the xcode editor.  One of the files was there with a .swift extension.   Type:  Default - Swift Source. Changing the location is what worked for me.  I changed it from "Relative to Group" to "Relative to Project" and the preview came up!

              • Re: Cannot preview SwiftUI
                JoshyMW Level 1 Level 1 (0 points)

                Potentially a slightly different problem but if you are using a Swift Package which has previews within it.

                 

                - The previews must be in the root folder of your sources, e.g. 'Sources/YourFramework/Previews.swift'.
                - The active target must be an application target.

                 

                Then the previews magically work.