daniel
daniel

Reputation: 23

xcode preview could not be built into project

canvas preview has an error just like that:

UnknownPreviewProviderError: Unknown preview provider "AboutView_Previews" 买就返.app does not contain a preview provider named "AboutView_Previews". Check your build settings to ensure the preview provider is compiled into your product. Mangled name: 3买就返18AboutView_PreviewsV

Error Domain=com.apple.dt.UITestingAgent Code=-1 "Preview provider "3买就返18AboutView_PreviewsV" does not exist" UserInfo={NSLocalizedDescription=Preview provider "3买就返18AboutView_PreviewsV" does not exist}

ihave check the "build setting" -> "build options" -> "Enable Previews" is Yes

import SwiftUI
struct ContentView: View {

    var body: some View {
        TabView {
            HomeView()
                .tabItem {
                    Image("tabbarHome")
                    Text("首页")
            }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Upvotes: 2

Views: 2066

Answers (3)

Alex F
Alex F

Reputation: 79

There was a similar error when the project name started with a digit (for example, 30-project-name). I just renamed the project with a name without numbers at the beginning

Upvotes: 1

izayl
izayl

Reputation: 508

I have the same issue when I modify the Product Name(at Target -> Packing -> Product Name) to Chinese word.

The right way to use Chinese word as App name:

  1. open info.plist
  2. add Bundle display name with the name you want.

Use this way to change app name will not effect SwiftUI Previews.

Upvotes: 2

Hardik Bar
Hardik Bar

Reputation: 1760

just change App name ("Buy back") it will solve your issue

Upvotes: 2

Related Questions