I'm just getting started with Combine. I have these questions for this situation:
- Is it accepted to have a tuple as a PassthroughSubject output?
- Is it accepted to have a completion handler as part of the PassthroughSubject output?
Example situation:
A SwiftUI log in view where I hand off logging in to another class and expect a result back:
struct LogInView: View {
var loginSubject = PassthroughSubject<(username: String, password: String, completion: (Error?) -> Void), Never>()
var body: some View {
Button {
loginSubject.send((username: "Jim", password: "qwerty123", completion: { error in
if let error = error {
// handle error
} else {
// navigate to app
}
}))
} label: {
Text("Log in")
}
}
}
I would like to know other possible solutions to this scenario (I'm not able to use the 'login helper' class directly in the SwiftUI view due to 'LogInView' being in a package and the 'log in helper' being in the main app) and/or if this would be generally accepted as a solution.