You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Problem with use of Binding

import SwiftUI


@main

struct MagnatoshApp: App {

var body: some Scene {

@Binding var b : Double

@State var fullDescStr = ""

var fullDesc : Binding<String> = Binding<String>(projectedValue: $fullDescStr)

WindowGroup {

ContentView(cmd: "", output: "", commandDesc: "", selCommand: Binding<Command?>(nil), description: "dddd" )

}

}

}



the line


@Binding var b : Double


gives the error


Missing argument for parameter 'projectedValue' in property wrapper initializer; add 'wrappedValue' and 'projectedValue' arguments in '@Binding(...)'


I have been at this for hours trying different combinations which end up going down a long series of code changes which get me nowhere


I think this is a compiler bug.Trying to find a work around is difficult

Posted on Jan 7, 2024 9:53 AM

Reply
3 replies

Jan 8, 2024 1:56 PM in response to Mark Szymczyk

The variable b didn't represent anything. It was a dummy variable put in to solve the real problem. I continued trying to get this to compile and in the end I do believe I fixed it by using a @State var instead of @Binding and did move it out of the App view too and subsequent compiler errors eventually lead me to a clean working build. I was coding in the dark because I didn't fully read up on State and Binding before turning my head towards them. I've only been programming with Swift for 2 weeks but have been a coder for 30 years or so. I intend to read up on them very soon but for now I can put the problem to bed. I shouldn't have been so hasty to blame the compiler. I think Swift is a very well thought out language and bow my head in shame for my insolence :-). Thanks for your help.


Sean

Problem with use of Binding

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.