This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol CanDisplayHeroDetailsScreen { | |
func displayHeroDetailsScreen(presenter aPresenter: Presenter) | |
} | |
extension CanDisplayHeroDetailsScreen where Self: UIViewController { | |
func displayHeroDetailsScreen(presenter aPresenter: Presenter) { | |
let detailsVC = HeroDetailsViewController.instantiateFromStoryboard(presenter: aPresenter) | |
navigationController?.pushViewController(detailsVC, animated: true) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class HeroListPresenter: Presenter { | |
private let service: HeroService | |
weak private var view : HeroListView? | |
... | |
init(service: HeroService) { | |
self.service = service | |
} | |
func attachView(view: HeroListView) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol HeroListView: NSObjectProtocol { | |
func startLoading() | |
func finishLoading() | |
func reloadHeroList() | |
func showEmptyListMessage() | |
func gotoHeroDetails(presenter aPresenter: HeroDetailsPresenter) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class HeroDetailsViewController: RootViewController { | |
override class func instantiateFromStoryboard(presenter aPresenter: Presenter) -> UIViewController { | |
let vc = UIStoryboard(name: "Hero", bundle: nil) | |
.instantiateViewController(withIdentifier: "HeroDetailsViewController") | |
as! HeroDetailsViewController | |
vc.presenter = aPresenter as? HeroDetailsPresenter | |
return vc | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RootViewController: UIViewController, StoryboardInitializable { | |
class func instantiateFromStoryboard(presenter aPresenter: Presenter) -> UIViewController { | |
fatalError("Override failed. Dependency injection not processed. Presenter injection hampered.") | |
} | |
// Preventing segue to support dependency injection | |
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { | |
fatalError("Segues should not be used. Presenter injection hampered.") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Presenter {} | |
protocol StoryboardInitializable { | |
static func instantiateFromStoryboard(presenter aPresenter: Presenter) -> UIViewController | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
... | |
} | |
class Apartment { | |
... | |
weak var person: Person? | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
let name: String | |
init(name: String) { | |
self.name = name | |
} | |
deinit { | |
print("\(name) is being deinitialized") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HTMLElement { | |
... | |
lazy var asHTML: () -> String = { [weak self] in | |
guard let htmlElement = self else { return "" } | |
return "<\(htmlElement.name)>\(htmlElement.text)</\(htmlElement.name)>" | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HTMLElement { | |
let name: String | |
let text: String? | |
lazy var asHTML: () -> String = { | |
return "<\(self.name)>\(self.text)</\(self.name)>" | |
} | |
init(name: String, text: String? = nil) { |
NewerOlder