Using Operators to build error-proof streams
For this section, go ahead and open the project in the code bundle named PublishersAndSubscribers_start. Take a look at the file ViewController.swift.
This file contains a User struct:
struct User: Codable {
let id: String
static var unknown: User {
return User(id: "-1")
}
}
The User struct is quite simple. It contains a String property id, and a static var named unknown that returns a User instance with id equal to -1. Apart from the User struct, the file contains the ViewController itself.
The view controller contains two methods:
- First,
postNotification(): This just fires a notification in the Notification Center that contains aUserinstance withidequal to123. The name of the notification isnetworkResult. - Second,
postNotificationThatFails(): This just fires a notification in the Notification Center that contains random data that is Base...