Post

Replies

Boosts

Views

Activity

BeginnerQuestion: Cannot use instance member 'user' within property initializer; property initializers run before 'self' is available
Hello, I have a struct like: struct User{     var user1 = "Arnold" var user2 = "Max" and then I have a SwiftUI-View where I want initialize a variable with this values, like this:     var users = User()     @State var user = users.user1 // UI Code I am starting with SwiftUI, I know to use MVVM-Pattern, but its only to understand why this gives me the error above and how to solve this kind of problems, where in the UI-View I want to dynamically change the value of a variable, for example with different buttons. For example changing the variable user from users.user1 to users.user2. Thanks and perhaps somebody can give me a link where I can found more about this beginner problem... perhaps I have overseen something in the documentation. Arnold
1
0
566
May ’21