1

I'm trying to "bind" information from a Class with State elements like this:

let people = People(name: "Jonnathan", firstSurname: "Bree")

@State private var name = people.name
@State private var firstSurname = people.firstSurname

but when I try to make this I have this error:

Cannot use instance member 'people' within property initializer; property initializers run before 'self' is available

or

Use of unresolved identifier 'self'

if a try to add .self before the object

Thank you so much!

1
  • make them lazy Commented Feb 12, 2020 at 19:59

1 Answer 1

1

Here is possible approach

let people = People(name: "Jonnathan", firstSurname: "Bree")

@State private var name: String
@State private var firstSurname: String

init() {
    _name = State<String>(initialValue: people.name)
    _firstSurname = State<String>(initialValue: people.firstSurname)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.