Reputation: 207
When I create a view I wish to login the user and when the login is complete, the view will change.
As I am quite new to SwiftUI it seems the way I am trying to this is not working. (I do know it has something to do with SwiftUI structs)
@State private var isLoading: Bool = true
init() {
userService.login { (didError, msg) in
}
}
ProgressView().disabled(isLoading).frame(alignment: .center)
When I try to do:
userService.login { (didError, msg) in
isLoading.toggle() or self.isLoading.toggle()
}
Xcode return: Escaping closure captures mutating 'self' parameter.
Does anyone know how I can make something like this work?
Upvotes: 6
Views: 1276
Reputation: 258305
Instead of init
call it in .onAppear
somewhere inside body
, like
var body: some View {
VStack {
// .. some content
}
.onAppear {
userService.login { (didError, msg) in
self.isLoading.toggle()
}
}
}
Upvotes: 9