Reputation: 63
I have this code:
struct TestView: View {
lazy var currentCompetitionID: String
@ObservedObject var fetchSingleCompetitionData = FetchSingleCompetitionData(option: "\(currentCompetitionID)")
var body: some View {
Text("\(fetchSingleCompetitionData.competitionList.name)")
}
}
I receive the error: "Cannot use instance member 'currentCompetitionID' within property initializer; property initializers run before 'self' is available"
Is there any way to initialize and use variable in the same view? Thank you!
Upvotes: 0
Views: 762
Reputation: 2824
fetchSingleCompetitionData
is being initialized as part of init
. Lazy vars are only available afterwards.
Consider moving the initialization to a fully-qualified initializer.
Upvotes: 2