可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答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.
回答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")
.color(Color.blue)
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = UIHostingController.init(rootView: ContentView())
回答3:
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!
回答4:
The preview only works on MacOS 10.15 Beta
You need to tap on Editor and Canvas Option in Xcode 11.0-Beta, alternatively you can tap on Editor -> Editor and Canvas from top options
Attached screenshots for refrence.
回答5:
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)
@canerkaseler
回答6:
This could be the effect if you upgraded Xcode to a higher beta version and got the following error message during the process:
Loading a plug-in failed
The plug-in “com.apple.dt.UVKit” at path
“/Applications/Xcode-beta.appDownloads/Xcode-beta.app/Contents/PlugIns/UVKit.framework”
could not be loaded. The plug-in or one of its prerequisite plug-ins
may be missing or damaged. The plug-in or one of its prerequisite
plug-ins may be missing or damaged and may need to be reinstalled.
The solution seems to be to upgrade the Catalina beta version to the same level. Here's the link to Apple's Beta Software Downloads.
回答7:
you have to install macOS at least version (10.15 or above)
回答8:
To preview and interact with views from the canvas in Xcode, ensure your Mac is running MacOS 10.15 beta.
Tools for SwiftUI development are only available when running on macOS 10.15 beta.
https://developer.apple.com/tutorials/swiftui/creating-and-combining-views
回答9:
As well as running MacOS Catalina [beta] it seems that you need to have the command line tools installed otherwise it fails and 'pauses' the canvas (this happened with Xcode 11 Beta 2). To install them run:
xcode-select --install
回答10:
Canvas preview only works after update MacOS 10.14 to 10.15
We have Mac OS Catalina Beta version (10.15)
Upgrade your system and it works. :)
Check this link.
回答11:
Some important checklist , please check one by one. If all this is done , you can easily get "Editor and Canvas" option.
Your MacOS version is equal or upper than 10.15
You are using at least Xcode 11 Beta or later. If you have Xcode 11 but your MacOS is bellow 10.15 , you won't be able to see the option.
Run the commands from Terminal :
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
and then
sudo xcodebuild -license
- If check list 1 and 2 is done , go to to the Preferences option and select command Line Tools. Preferences -> Locations and assigning the Command Line Tools to Xcode 11/Beta.
Most of the time, option 4 is the problem.