When crash by assertNoFailure, I cannot see the message.
smaple code
View
import SwiftUI
struct ContentView: View {
@ObservedObject private var viewModel = ContentViewModel()
var body: some View {
Button(action: { viewModel.crash() }, label: { Text("button") })
}
}
ViewModel
import Foundation
import Combine
class ContentViewModel: ObservableObject {
var cancellables = Set<AnyCancellable>()
private enum AddOneError: Swift.Error {
case error
}
private func addOnePublisher(_ n: Int) -> AnyPublisher<Int, AddOneError> {
Deferred {
Future { (promise) in
guard n < 10 else {
promise(.failure(AddOneError.error))
return
}
promise(.success(n + 1))
}
}
.eraseToAnyPublisher()
}
func crash() {
addOnePublisher(10)
.assertNoFailure("I want to disply this message.")
.sink { (completion) in
switch completion {
case .finished:
break
case .failure(let error):
print(error)
}
} receiveValue: { (n) in
print(n)
}
.store(in: &cancellables)
}
}
when crash
if I use
.catch { error -> AnyPublisher<Int, Never> in fatalError("I can see this message") }
instead of assertNoFailure I can see log
Fatal error: I can see this message
How can I see the prefix of assertNoFailure? And if not, when is it used?