0

I have a prefix operator in my framework(Swift Package):

prefix operator !

public prefix func !(value: Binding<Bool>) -> Binding<Bool> {
    Binding<Bool>(
        get: { !value.wrappedValue },
        set: { value.wrappedValue = !$0 }
    )
}

Used in source code like this, xcode issues 'Cannot convert value of type 'Binding' to expected argument type 'Bool'. Cannot convert value of type 'Bool' to expected argument type 'Binding'':

struct TestView: View {
    @State private var isOn = false

    var body: some View 
        Toggle("", isOn: !$isOn)
    }
}

After I copy the code of prefix operator ! into source code from framework, everything good.

Could it be that we could not use prefix operator from 'framework'?

foolbear
  • 726
  • 1
  • 7
  • 19

1 Answers1

0

Why are you adding another View struct to the PreviewProvider?

Do you have the same problem with the following code?

struct ContentView: View {
    @State private var isOn = false

    var body: some View {
        Toggle("", isOn: !$isOn)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
  • Not working either. what's wrong? So It's nothing todo with PreviewProvider. about framework only. Let me edit problem. – foolbear Mar 22 '23 at 12:49
  • I put TestView into PreviewProvider because it's just for preview. I think it's no any problem, right? And thanks for your response, or I report a wrong problem. and sorry for my mistake. – foolbear Mar 22 '23 at 13:02