Learn how to simplify the flow of data in your Swift application using a Flux / Redux / Elm like architecture inspired by functional programming.
Check out jarsen/Reactor on github.
16. SPOT THE BUG!
class ViewController: UIViewController {
@IBOutlet var titleLabel: UILabel!
var name: String? {
didSet {
titleLabel.text = name
}
}
}
17. SPOT THE NEW BUG!
class ViewController: UIViewController {
@IBOutlet var titleLabel: UILabel?
var name: String? {
didSet {
titleLabel?.text = name
}
}
}
18. THE IMPLICITLY UNWRAPPED OPTIONAL DANCE
class ViewController: UIViewController {
@IBOutlet var titleLabel: UILabel?
var name: String? {
didSet {
configureView()
}
}
func configureView() {
titleLabel?.text = name
}
override func viewDidLoad() {
super.viewDidLoad()
configure()
}
}
25. ASYNC EVENTS
struct Update<T>: Event {
var value: T
}
class UserService {
// this type of function is also knows as an `EventEmitter`
func getUsers(state: State, reactor: Reactor<State>) -> Event? {
myNetworkThing.get("users") { json in
// transform to user object, using Marshal, of course
reactor.perform(event: Update(value: users))
}
}
}
37. OTHER RESOURCES
> A composable pattern for pure state machines with
effects by Andy Matuschak
> Unidirectional Data Flow in Swift by Benjamin Encz
> Elmification of Swift
> MCV-N Swift Talk by Marcus Zarra
> Backend-driven Native UIs by John Sundell