Integrating SwiftUI into existing project

Trying to add a SwiftUI view to an existing project but I get the following error message above the preview canvas:


> Cannot preview in this file - current target needs adjusted build settings


Anyone know what build setting needs updating? This is a Swift 5 project, targetting iOS13.

Replies

Also have a similar problem, when I try to preview a SwiftUI in an existing project I get:

(I am running macOS 10.15 beta & Xcode 11 beta)


"Error Domain=com.apple.dt.UITestingAgent Code=-1 "Preview provider "10[APPNAME]20SwiftUIView_PreviewsV" does not exist" UserInfo={NSLocalizedDescription=Preview provider "10[APPNAME]20SwiftUIView_PreviewsV" does not exist}


I noticed in the SwiftUI tutorials that when creating a new project you have to check the "Use SwiftUI" checkbox, so I'm guessing it is some sort of build/project/info.plist setting that needs to be changed?


I tried to compare a new project using SwiftUI with my existing project but couldn't find any SwiftUI settings as far as the project was concerned.

A SwiftUI file created from the default template includes a PreviewProvider guarded by an `#if DEBUG` statement. In order to include this in the binary used by Xcode's preview cancas, open your project settings, expand "Active Compilation Conditions" (SWIFT_ACTIVE_COMPILATION_CONDITIONS) and add "DEBUG" in the debug configuration.