8. Структура модуля
class TodayWeatherPresenter: TodayWeatherModuleInput,
TodayWeatherViewOutput {
//MARK: TodayWeatherModuleInput
//MARK: TodayWeatherViewOutput
}
•Ошибка: Declarations from extensions cannot be overriden yet
•Нарушается целостность кода
9. Структура модуля
class TodayWeatherPresenter: TodayWeatherModuleInput,
TodayWeatherViewOutput {
weak var view: TodayWeatherViewInput!
var interactor: TodayWeatherInteractorInput!
var router: TodayWeatherRouterInput!
}
•Корректную конфигурацию проверять в тестах
13. Конфигурация модуля: Typhoon
typealias WeatherItem = (String, Int)
@objc protocol TodayWeatherInteractorInput {
func getWeatherData() -> WeatherItem
}
method cannot be marked @objc because ... cannot be represented in Objective-C
Получаем ошибку:
14. Конфигурация модуля: Swift DI frameworks
Swinject
let container = Container()
container.register(TodayWeatherRouterInput.self)
{ _ in TodayWeatherRouter() }
container.register(TodayWeatherViewOutput.self)
{ registrator in
TodayWeatherPresenter(router:
registrator.resolve(TodayWeatherRouterInput.self)!)
}
//Configurator
let presenter =
container.resolve(TodayWeatherRouterInput.self)
15. Конфигурация модуля: Swift DI frameworks
Dip
let dependencyContainer = DependencyContainer()
{ container in
container.register
{ TodayWeatherRouter() as TodayWeatherRouterInput }
container.register {
TodayWeatherPresenter(router:
try! container.resolve() as TodayWeatherRouterInput)
as TodayWeatherViewOutput
}
}
//Configurator
let router = try! dependencyContainer.resolve() as
TodayWeatherRouter
16. Swift DI frameworks: Проблемы
•Существующие решения - Service locators
•Runtime возможности только для NSObject наследников
•Readonly Reflection API
17. Конфигурация модуля: Storyboard DI
class TodayWeatherModuleInitializer: NSObject {
@IBOutlet weak var
viewController: TodayWeatherViewController!
override func awakeFromNib() {
let configurator =
TodayWeatherModuleConfigurator()
configurator.
configureModuleForViewInput(viewController)
}
}
18. Конфигурация модуля: Конфигуратор
class TodayWeatherModuleConfigurator:
BaseModuleConfiguratorProtocol {
func configureModuleForViewInput<UIViewController>
(viewInput: UIViewController) {
if let todayWeatherController =
viewInput as? TodayWeatherViewController {
configure(todayWeatherController)
}
}
//...
}
23. enum TimeOfDay: String {
case Now = "now"
case Morning = "morning"
case Afternoon = "afternoon"
case Evening = "evening"
case Night = "night"
}
struct WeatherItem {
let timeOfDay: TimeOfDay?
let weather: String?
let temperature: String?
let temperatureIconName: String?
}
PONSO -> POSO
24. PONSO -> POSO
•Immutability, thread safe из коробки
•struct и enum поддерживают большинство возможностей классов
•Оптимизации
38. Зачем переходить на Swift
• Меньше файлов, выразительный синтаксис
• Модификаторы доступа, пространства имен
• Строгая типизация и явный nil
• Immutability из коробки
• Мультипарадигменность
39. Viper+ Swift
• Революции не случилось
• Модули пишутся быстрее
• Можно эффективно использовать возможности языка
• Тесты пишутся медленнее