SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
5.
#Swift3Arch
Job Description
Understand the problem
Identify the right set of pieces
Put proper names
Make them run together properly
6.
#Swift3Arch
Social Network Option A
Social Network
7.
#Swift3Arch
Video
Text
Image
Social Network Option B
User PostGroup
Discussion
Promotion
DM
8.
#Swift3Arch
Single Responsibility
Principle
View
Controller
Presenter
View Model
Model
Presentation
logic
Business
Logic
Data
Source
Data
Source
Data
Source
Navigation
10.
#Swift3Arch
Making it work
Objects require other objects to work ->
Dependencies
Each object creates its dependencies
Bad idea™
• Another responsibility
• What if we want to use it with different
sets of pieces?
18.
#Swift3Arch
Dip
Created by Olivier Halligon, maintained by Ilya
Puchka
Beautifully simple
Nice way to inject in Storyboards
Scopes, Named definitions, Runtime arguments,
Circular dependencies, Auto-wiring & Auto-injection,
Type forwarding, Storyboards integration, Weakly
typed components, Easy configuration, Thread
safety, Helpful error messages, and configuration
validation.
19.
#Swift3Arch
Dip
func configure(container: DependencyContainer) {
container.register(.unique) { InMemoryRepo() }
container.register(.unique) { try UseCaseFactory(entityGateway:
container.resolve() as InMemoryRepo) }
DependencyContainer.uiContainers = [showProgrammersListModule]
}
let showProgrammersListModule = DependencyContainer { container in
container.register() { try ProgrammersListPresenter(useCaseFactory:
container.resolve() as UseCaseFactory) }
container.register(tag: "ProgrammersTableVC")
{ ProgrammersTableViewController() }
.resolvingProperties { container, viewController in
viewController.presenter = try container.resolve() as
ProgrammersListPresenter
}
}
extension ProgrammersTableViewController: StoryboardInstantiatable {}
20.
#Swift3Arch
Swinject
Created by Jakub Vano, Wolfgang Lutz, Yoichi
Tagala
Pure Swift Type Support, Injection with
Arguments, Initializer/Property/Method
Injections, Initialization Callback, Circular
Dependencies, Object Scopes, Reference &
Value Types, Self-registration, Container
Hierarchy, Property Injection from Resource
files, Thread Safety, Modular Components,
Storyboard
21.
#Swift3Arch
Cleanse
Created by Square
Early version, but promising
24.
#Swift3Arch
Java for Android
Standard annotations for DI (JSR330)
Introspection & Reflection
Many frameworks available
Some owned by Google (Guice & Dagger
2)