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!
fetchSingleCompetitionData
is being initialized as part of init
. Lazy vars are only available afterwards. Consider moving the initialization to a fully-qualified initializer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.