Xcode 11: Canvas does not show up
Solution 1
You need to be on Catalina macOS version (10.15), as stated in official tutorial
Be warned: Catalina doesn't support 32-bit applications, some old apps will stop working after update.
Solution 2
you can still see the live view (without Catalina installed ) with the playgrounds.
using UIHostingController
.
import UIKit
import SwiftUI
import PlaygroundSupport
struct ContentView : View {
var body: some View {
Text("Hello World")
.foregroundColor(Color.blue)
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = UIHostingController.init(rootView: ContentView())
Solution 3
Update Mac OS version 10.15 or upper version. Update Xcode 11 or upper version. After that click Editor > Canvas for code preview.
Bonus: If you would like to see code preview left side, you can change layout from Menu Icon > Layout > Canvas Right. (I shared screenshot)
Solution 4
To further add to the other answer, as per the official tutorial from Apple:
To preview and interact with views from the canvas in Xcode, ensure your Mac is running macOS 10.15 beta.
Unfortunate that I can't run it right now since the beta was just released and I don't have a spare Mac!
Solution 5
I tried all these steps, but then realized I did not have my PreviewProvider
set up in my file. Without this, the preview won't show up.
Make sure you have it set up like this:
struct YourView_Previews: PreviewProvider {
static var previews: some View {
YourView()
}
}
Then you can follow the advice of the other answers in this thread and your canvas window should pop right up.
stk
Updated on July 09, 2022Comments
-
stk almost 2 years
I´m trying to get the new Canvas feature from Xcode 11 running, but the Canvas won´t show up. What am I doing wrong?
I just created a new default project (single view app), compiled it and activated 'Editor > Editor and Canvas'. I can navigate to each file in the project, nothing shows up.
What else does need to be done?
-
Karol Kulesza almost 5 yearsIt should be clearly communicated in Xcode, when you try to switch to
Editor and Canvas
mode. "Let's just do nothing and force the user to google why it's not showing up" approach is a BAD approach. -
zero3nna almost 5 yearsbut this is not the new canvas, its just the live view if you run the app. you can do that as well with a project
-
zero3nna almost 5 years@KarolKulesza thats true, even on the dev portal its showing requirements for the new iOS:
Installation requires macOS 10.15 beta or Xcode 11 beta
but not even a note for xcode11 -
Eddie Eddie Eddie almost 5 yearsThat might be cool, but that's not quite the question. After reading the other answers, it's clear Apple just didn't place the "Xcode 11 beta runs on Mojave but runs more of the features best on Catalina" notice in enough places. Preview is one the features I'm most excited about using.
-
Teejay almost 5 yearsNow it states that when opening the canvas.
-
strangetimes about 4 yearsShockingly this is the only thing that worked. Seems like somehow the file stopped being recognized as a SwiftUI file till a new one was created. No amount of rebooting and restarting Xcode helped, even closing / showing the canvas etc. Copy contents, Delete the file, create a new one and paste. Voila.
-
Allen King over 3 yearsDid this on Big Sur 11.1, nada. Still something else.