A talk I prepared for the third edition of the Learn Swift Milan meetup, hosted by Bending Spoons, focusing on the architecture we use to develop all of our iOS apps.
5. Motivation
• Our code must manage more state than ever
before: server responses and cached data, as well
as locally created data that has not yet been
persisted to the server
• This complexity is difficult to handle as we're mixing
two concepts that are very hard for the human
mind to reason about: mutation and
asynchronicity.
Courtesy of the Redux docs
14. • It enforces an unidirectional data flow: this makes
the logic predictable and easier to understand
• It encourages data normalization, so that you don't
end up with multiple, independent copies of the
same data that are unaware of one another
• It allows the creation of powerful debugging tools
18. let myMiddleware: StoreMiddleware = { getState, dispatch in
return { next in
return { action in
let previousState = getState()
next(action)
let currentState = getState()
// do something...
}
}
}
19. • Persist and restore the app state
• Track metrics by detecting when an action is dispatched
or when the state changes
• Debugging: log actions, measure execution time
• …
35. Navigation
• Navigate by dispatching Actions
• Isolate View Controllers presentation logic
• How do we reconcile navigation state managed by
UIKit and app state managed by Katana? 🤔
36. • Two main navigation actions: Show, Hide
• View Controllers must implement the Routable protocol
dispatch(Show(Screen.mainEditor))
dispatch(Hide())
37. enum Screen: String {
case mainTabbar
case feed
case feedSectionDetail
case createArt
case createArtFromPhoto
}
extension CreateArtStack: Routable {
var routeIdentifier: RouteElementIdentifier {
return Screen.createArt.rawValue
}
...
39. References
• Katana — github.com/bendingspoons/katana-swift
• Tempura will be open sourced soon
• Want to know more? bendingspoons.com
Francesco Di Lorenzo // @frankdilo