I suggest you create a variable somewhere in your app, probably in your data model, to hold the pressed button's value e.g. var pressedButton : letters?. Then in your Button(action: { pressedButton = item }. NOTE: if pressedButton is defined outside of this view, then you need to refer to it correctly e.g. myDataModel.pressedButton
pressedButton is defined as Optional, because to start with no button has been pressed. When your app goes to use pressedButton it needs to check that a button has indeed been pressed, i.e. pressedButton != nil. You can display the pressedButton value as pressedButton.rawValue
There are various ways of then dealing with a change to the pressedButton, e.g 1) a didSet on the pressedButton var, 2) an @ObserverableObject entity that contains @Published pressedButton
BTW, the Swift convention is that type definitions, including enums, have a name starting with Uppercase e.g. Letter and instances use an initial-lowercase name. So, in your example it would be
enum Letter : String {
case: a,b,c,d,e,f,g
}
let buttons : [[Letter]] = [
[.a, .b, .c, .d, .e, .f, .g],
Best wishes, Michaela
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: