4

I'm trying to create a new XCode project, plain brand new and I can run it on the simulator, but on the canvas it says: Cannot preview in this file - active scheme does not build this file If on top of that I start adding macOS support, it says:

'appName' is annotated with @main and must provide a main static function of type () -> Void or () throws -> Void. It also says:

Cannot find type 'App' in scope

Cannot find type 'Scene' in scope

Regarding mac support I was reading there is a workaround, even though I tried and the error remains.

As for the active scheme, I read this, but doesn't help. I mean... there is only 1 scheme in a new project and it's selected automatically

I would assume a plain hello world project would work, what's going on?

ElKePoN
  • 822
  • 11
  • 21

2 Answers2

3

SwiftUI 2.0 on macOS is available only starting from Big-Sur macOS 11.0

@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
public protocol App {
                    ^^^^^^^^^^^^
Asperi
  • 228,894
  • 20
  • 464
  • 690
  • Maybe I should edit the title then, I have Catalina, I was assuming it was SwiftUI 2.0, the thing is that as soon as I create a new project it fails. I do have XCode 12 tho. I'm updated XCode and everything, I don't understand why a new project gives this error – ElKePoN Oct 07 '20 at 13:46
  • Yes, Xcode 12 allows to create new macOS project with SwiftUI 2.0, but you cannot target it for and run it on Catalina. For Catalina you should create new project with SwiftUI UIKit life-cycle and use only SwiftUI 1.0 API. – Asperi Oct 07 '20 at 13:59
  • I see, that's probably why. So if I create a `SwiftUI App` life cycle now on Catalina will I be able to run macOS support when Big Sur release? It's kind of a dumb question but I want to make sure. – ElKePoN Oct 07 '20 at 14:06
  • 1
    Yes, it will, but if you're going to develop for macOS 11 it is better to develop on macOS 11. )) – Asperi Oct 07 '20 at 14:09
  • new Swift/Xcode coder here and the start is pretty rough :D i understand what you mean @Asperi, but no idea how to implement that Catalina/SwiftUI 1.0 start. any help possible? – godbout Nov 15 '20 at 16:39
  • argh, of course found it after posting. need to create a new app with the AppDelegate life-cycle option rather than SwiftUI. was hidden in the dropdown :)) – godbout Nov 15 '20 at 16:47
1

Regarding the macOS support is what Asperi mentioned, on Catalina has problems supporting mac on XCode 12.

As for the new project failing, I found that if I press Cmd + Opt + P, it would build it on the Canvas fine. I had tried clicking "Try again" on the canvas which I would assume is the same and didn't work. You don't need to delete the file and create a new one nor select any target since it's a new project and the target is selected automatically. Also the @Main doesn't have to be changed to run on iOS and iPad, for macOS support just wait until Big Sur releases.

ElKePoN
  • 822
  • 11
  • 21