of values over time. • Defines how values and errors are produced • Value type -> `Struct` • Allows registration of a `Subscriber` https://developer.apple.com/videos/play/wwdc2019/722/ 6
values • Subscribes to a `Publisher` (“upstream”) • Sends result to a `Subscriber` (“downstream”) • Value type -> `Struct` https://developer.apple.com/videos/play/wwdc2019/722/ 8
the framework when changed. @available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) @available(*, deprecated, message: "Conform to Combine.ObservableObject and Swift.Identifiable") public protocol BindableObject : ObservableObject, Identifiable { /// A type that publishes an event when the object has changed. associatedtype PublisherType : Publisher where Self.PublisherType.Failure == Never /// An instance that publishes an event immediately before the /// object changes. /// /// A `View`'s subhierarchy is forcibly invalidated whenever /// the `willChange` of its `model` publishes an event. var willChange: Self.PublisherType { get } } 13
public protocol ObservableObject : AnyObject { /// The type of publisher that emits before the object has changed. associatedtype ObjectWillChangePublisher : Publisher = ObservableObjectPublisher where Self.ObjectWillChangePublisher.Failure == Never /// A publisher that emits before the object has changed. var objectWillChange: Self.ObjectWillChangePublisher { get } } 14
value of an entity with stable identity. @available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *) public protocol Identifiable { /// A type representing the stable identity of the entity associated with `self`. associatedtype ID : Hashable /// The stable identity of the entity associated with `self`. var id: Self.ID { get } } @available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *) extension Identifiable where Self : AnyObject { /// The stable identity of the entity associated with `self`. public var id: ObjectIdentifier { get } } 15
using SwiftUI, Combine & MVVM as one of the architecture ideas • APIs of Combine still has (breaking) changes ◦ BindableObject and @ObjectBinding are deprecated • Let’s discuss about best practice of SwiftUI architecture • Documents ◦ Qiita: https://qiita.com/akifumi1118/items/aa5734b1f14d57072456 ◦ SwiftUI: https://github.com/akifumi/mvvm-with-combine-in-swiftui ◦ UIViewController: https://github.com/akifumi/mvvm-with-combine-in-uiviewcontroller 25
Practice ◦ https://developer.apple.com/videos/play/wwdc2019/721/ • Data Flow Through SwiftUI ◦ https://developer.apple.com/videos/play/wwdc2019/226/ 26