Swift 无法转换类型为';字符串';至';装订<;字符串>';

Swift 无法转换类型为';字符串';至';装订<;字符串>';,swift,swiftui,Swift,Swiftui,我正在尝试创建子视图,但出现以下错误: SignInButtons.swift:54:34: error: cannot convert value of type 'String' to expected argument type 'Binding<String>' signInUrl: "http://www.apple.com", ^~~~~~~~~~~~~~~~~~

我正在尝试创建子视图,但出现以下错误:

SignInButtons.swift:54:34: error: cannot convert value of type 'String' to expected argument type 'Binding<String>'
                      signInUrl: "http://www.apple.com",
                                 ^~~~~~~~~~~~~~~~~~~~~~struct 
====================

ContentView: View {

import SwiftUI

struct ContentView: View {
    //our color palette
    let colorWheel : [String: Color] = [
        "darkOrange"    : Color.init(hex: "F1615D"),
        "mediumOrange"  : Color.init(hex: "FF8761"),
        "darkYellow"    : Color.init(hex: "FFC575"),
        "lightYellow"   : Color.init(hex: "F1FAC6"),
        "brightAqua"    : Color.init(hex: "79E6E3"),
        "lightAqua"     : Color.init(hex: "a8e6cf"),
        "limeGreen"     : Color.init(hex: "dcedc1"),
        "brightPeach"   : Color.init(hex: "ff8b94"),
        "mediumPeach"   : Color.init(hex: "ffaaa5"),
        "lightPeach"    : Color.init(hex: "ffd3b6"),
    ]

    @State private var backgroundColor:Color
    @State private var signInUrl = "http://www.apple.com"
    @State private var showModal = false
    private var detailSize = CGSize(width: 0, height: UIScreen.main.nativeBounds.height)

    var body: some View {
        ZStack{
            VStack {
                AnimatedContentView()
                Spacer()

                SignInButtons(backgroundColor: self.backgroundColor,
                              signInUrl: self.$signInUrl,
                              showModal: self.$showModal)

                Spacer().frame(height: CGFloat(100))
            }
            .onAppear() {
                self.backgroundColor = self.colorWheel["darkOrange"]!
            }
            .foregroundColor(Color.black.opacity(0.7))
            .edgesIgnoringSafeArea(.all)

            VStack {
                AskForEmailView(showModal: self.$showModal)
                .offset( self.showModal ? CGSize.zero : detailSize)

            }

        } //end zStack
    }
}



struct ContentView_Previews: PreviewProvider {
    enum MyDeviceNames: String, CaseIterable {
        case iPhoneXrMax = "iPhone 11 Pro Max"
//        case iphoneX = "iPhone X"
//        case iPhoneXs = "iPhone Xs"
//        case iPhoneXsMax = "iPhone Xs Max"
//        case iPad = "iPad Pro (11-inch)"

        static var all: [String] {
            return MyDeviceNames.allCases.map { $0.rawValue }
        }
    }
    static var previews: some View {
        //ContentView()
        Group {
            ForEach(MyDeviceNames.all, id: \.self) { deviceName in
                ContentView(detailSize: CGSize.zero)
                      .previewDevice(PreviewDevice(rawValue: deviceName))
                      .previewDisplayName(deviceName)
            }
//            ForEach(MyDeviceNames.all, id: \.self) { deviceName in
//                ContentView()
//                    .colorScheme(.dark)
//                    .background(Color.black)
//                    .edgesIgnoringSafeArea(.all)
//                    .previewDevice(PreviewDevice(rawValue: deviceName))
//                    .previewDisplayName(deviceName)
//            }
        }

    }
}

import SwiftUI

struct SignInButtons: View {
    var backgroundColor:Color
    @Binding var signInUrl : String
    @Binding var showModal : Bool

    var body: some View {
        VStack(spacing: 0) {
            //using text w tap gesture - to do: make into its own component
            Text("Sign in with Facebook")
                .fontWeight(.light)
                .font(.title)
                .padding()
                .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 70, alignment: .top)
                .background(Color.blue.opacity(0.8))
                .foregroundColor(Color.white)
                .onTapGesture {
                    self.signInUrl = "http://www.facebook.com"
                    self.showModal.toggle()
                }

            //using a button
            Button(action: {
                print("Button Pushed")
                self.signInUrl = "http://www.google.com"
                self.showModal.toggle()
            }) {
                Text("Sign in with Google")
                    .fontWeight(.light)
                    .font(.title)
                    .padding()
                    .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 70, alignment: .top)
                    .background(backgroundColor)
                    .foregroundColor(Color.white)
            }
        }
        .navigationBarHidden(true)
        .edgesIgnoringSafeArea([.top, .bottom])
    }
}

struct SignInButtons_Previews: PreviewProvider {
    static var previews: some View {
        SignInButtons(backgroundColor: Color.blue,
                      signInUrl: "http://www.apple.com",
                      showModal: false)
    }
}

下面是一种可能的方法-使用常量绑定进行预览

struct SignInButtons_Previews: PreviewProvider {
    static var previews: some View {
        SignInButtons(backgroundColor: Color.blue,
                      signInUrl: .constant("http://www.apple.com"),
                      showModal: .constant(false))
    }
}

为什么您总能找到解决方法,如果我需要使用变量,因为它可以是泛型值,这是我看到的第二个答案,但仍然无法使用observedObject中的字符串设置Text():((
struct SignInButtons_Previews: PreviewProvider {
    static var previews: some View {
        SignInButtons(backgroundColor: Color.blue,
                      signInUrl: .constant("http://www.apple.com"),
                      showModal: .constant(false))
    }
}