I have SwiftUI project, and I want to use register for my project, it throw an error as a "Function is unused" for signUp
in this line of code:
Button {
self.viewModel.signUp
} label: {
Text("Register")
.padding()
}
I do not know why?
struct Register: View {
@ObservedObject private var viewModel: RegisterViewModel
@State var pushActive = false
init(state: AppState) {
self.viewModel = RegisterViewModel(authAPI: AuthService(), state: state)
}
var body: some View {
Button {
self.viewModel.signUp
} label: {
Text("Register")
.padding()
}
}
viewmodel:
class RegisterViewModel: ObservableObject {
@Published var email: String = ""
@Published var password: String = ""
@Published var state: AppState
private var cancellableBag = Set<AnyCancellable>()
private let authAPI: AuthAPI
init(authAPI: AuthAPI, state: AppState) {
self.authAPI = authAPI
self.state = state
}
func signUp() {
authAPI.signUp(email: email, password: password)
.receive(on: RunLoop.main)
.map(resultMapper)
.store(in: &cancellableBag)
}
}
}