中〜大規模 Swift 開発における依存オブジェクト解決の方法を考える
- DI (Dependency Injection) とは?
- DIの基本的な話:知っている人が多かったら省略予定
- コンテナ (Swinject) を用いた DI
- Swinject の DI コンテナを用いた 動的DIの話
- Swiftにおける静的 DI
| // | |
| // Database.swift | |
| // Model | |
| // | |
| // Created by mono on 2017/10/14. | |
| // Copyright © 2017 Masayuki Ono All rights reserved. | |
| // | |
| import Foundation | |
| import FirebaseCore |
| /* | |
| * SwinjectでSegueにInjectするSegueOperatorTypeを指定する。 | |
| * nameにSegueのIdentifierを指定する。 | |
| */ | |
| container.register(SegueOperatorType.self, name: "BundlesSegue") { _ in | |
| return SegueOperator { | |
| _, _ in | |
| print("test") | |
| } | |
| } |
| class BundleSegue: ConfigurationSegue { | |
| typealias Source = BundlesViewController | |
| typealias Destination = BundleViewController | |
| typealias First = BundlesViewController | |
| typealias Second = BundleViewController | |
| override func inject() { | |
| destinationController.viewModel = resolver.resolve(BundleViewModelType.self) |
| // Amazonの注文履歴をTSV形式で出力するスクリプト | |
| // | |
| // 2015-01-01 時点での DOM 構造に対応, GoogleCrome, Opera でテスト済。 | |
| // formatEntry関数を書き換えれば自由な書式で出力できます。 | |
| // | |
| // 参考: | |
| // - Amazonの注文履歴をCSV形式にして出力するスクリプト | |
| // https://gist.github.com/arcatdmz/8500521 | |
| // - Amazon で使った金額の合計を出す奴 (2014 年バージョン) | |
| // https://gist.github.com/polamjag/866a8af775c44b3c1a6d |
| import Darwin | |
| // Uses printf() formatting | |
| // Returns String! because vasprintf() can fail to allocate | |
| func Format(fmt: String, args: CVarArg...) -> String! { | |
| var chars: UnsafePointer<CChar> = nil | |
| let n = withUnsafePointer(&chars) { | |
| charp in | |
| withVaList(args) { | |
| va_list in |