SwiftUI error with preview: "not building -Onone"

I can't build even a simple SwiftUI file in my project without running into an error in the Preview pane, which says "Cannot preview this file - not building -Onone".

When I tap the little info button, it shows me this message:

OptimizationLevelError: not building -Onone
"CJDashboard.app" needs -Onone Swift optimization level to use previews

This is with Xcode11.5. My project file has been around for quite a while, but I keep updating it frequently, so I'm not sure what setting I've missed. The code compiles file, but I can't see any live previews with SwiftUI.

Can anyone help me figure this out? Thanks.
Answered by Developer Tools Engineer in 613497022
This is driven by the "Optimization Level" setting in the build settings for the target that contains the file you're editing. One of two things is happening…
  1. That value accidentally got set to something other than Onone for your debug build

  2. The scheme you're using has a configuration set that isn't your debug one. By default, projects come with a "Debug" and "Release" config. The "Debug" config is configured to build Onone, which means without optimizations. And the "Release" config is configured to build with optimizations. You just need to double check the build configuration selected for your scheme is your debug (usually "Debug") one.

Accepted Answer
This is driven by the "Optimization Level" setting in the build settings for the target that contains the file you're editing. One of two things is happening…
  1. That value accidentally got set to something other than Onone for your debug build

  2. The scheme you're using has a configuration set that isn't your debug one. By default, projects come with a "Debug" and "Release" config. The "Debug" config is configured to build Onone, which means without optimizations. And the "Release" config is configured to build with optimizations. You just need to double check the build configuration selected for your scheme is your debug (usually "Debug") one.

15
SwiftUI error with preview: "not building -Onone"
 
 
Q