Observing and broadcasting
The usual solution to observe and broadcast is to use NotificationCenter:
final class Post { // 1
var title: String
var body: String
init(title: String, body: String) {
self.title = title
self.body = body
}
}
extension Notification.Name { // 2
static let LTHPostReceived = Notification.Name(rawValue: "com.rolandleth.com.postReceivedNotification")
}
final class PostCreationController: UIViewController { // 3
private let post: Post
// [...]
private func savePost() { // 4
// [...]
let userInfo = ["post": post] // 5
let notification = Notification(name: .LTHPostReceived, object: nil, userInfo: userInfo) // 6