Different Build Schemes -> Error: -Onone Swift optimization level to use previews

I have a sample SwiftUI iOS app. As shown in the screenshot below, my project has three configurations: Debug, MyDebug, Release.

If I select the Debug or MyDebug scheme, I get a preview. But if I select the Release scheme, I get an error that says the following.

”***.app” needs -Onone Swift optimization level to use previews (current setting is -O)

, where *** is the app name.

It probably has nothing to do with the Preview error, but the Info.plist has a dictionary such that the key name is devMode, and the value is $(DEVMODE). And I have a user-defined setting as shown below.

My ContentView has the following.

import SwiftUI

struct ContentView: View {
    @State private var state: String = ""
    
    var body: some View {
        VStack {
            Text("Hello, world!: \(state)")
        }
        .onAppear {
            if let devMode = Bundle.main.object(forInfoDictionaryKey: "devMode") as? String {
                print("Development mode: \(devMode)")
                state = devMode
            }
            if let path = Bundle.main.path(forResource: "Info", ofType: "plist") {
                if let dict = NSDictionary(contentsOfFile: path) {
                    print("**** \(dict)")
                }
            }
            #if DEBUG
                print("Debug")
            #elseif MYDEBUG
                print("MyDebug")
            #else
                print("Que?")
            #endif
        }
    }
}

#Preview {
    ContentView()
}

So my question is how I get the preview for all three build schemes? Muchos thankos.

Hi @Tomato,

I need more information from the previews diagnostics. Please follow the directions in the following post and reply here with the Feedback ID, once submitted, and we'll look into this.

Gathering Required Information for Troubleshooting Xcode Previews or Swift Previews Issues

https://developer.apple.com/forums/thread/775027

Cheers,

Paris X Pinkney |  WWDR | DTS Engineer

Hello, Paris and DTS.

My sample iOS app doesn't crash if I run it with a simulator or an actual device although the preview canvas shows an error for a selective build scheme. So I am afraid that I have nothing to report to you. I have installed the said profile as shown below.

It's hard to locate the one that I need to look for since the list has several dozen items. Yet, based on Today's date, I don't find one.

So what's next?

Different Build Schemes -> Error: -Onone Swift optimization level to use previews
 
 
Q