Problem using prefix operator from framework
Asked Answered
S

1

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'?

Swindle answered 22/3, 2023 at 3:39 Comment(0)
V
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()
    }
}
Vert answered 22/3, 2023 at 12:17 Comment(2)
Not working either. what's wrong? So It's nothing todo with PreviewProvider. about framework only. Let me edit problem.Swindle
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.Swindle

© 2022 - 2024 — McMap. All rights reserved.