Slide 1

Slide 1 text

WWDC2016Ͱ࿩͞Εͨ Dependency InjectionΛ ׆༻ͯ͠ϦϑΝΫλϦϯά Potatotips-32, 2016೥8݄23೔ @yoichitgy - Yoichi Tagaya

Slide 2

Slide 2 text

DI Framework for Swift https://github.com/Swinject/Swinject Swinject

Slide 3

Slide 3 text

SwinjectΛ஌͍ͬͯΔͱ༗རͳब৬ઌ • Atlassian • Implement unit tests and performance tests in Objective-C and Swift using XCTest, OCMock, Swinject... • https://www.smartrecruiters.com/Atlassian/93336663-ios-developer • MealPass • Familiarity with dependency injection libraries such as swinject • http://garysguide.com/jobs/up0gwed/Software-Engineer-at-MealPass-New-York-NY • Location Labs • We are using in our iOS products, including Cocoapods, Typhoon/ Swinject, Realm, PromiseKit, Alamofire, Amplitude...
 https://www.latitude.work/locationlabs/emeryville/senior-software-engineer-ios • МАДЖЕСТИ • 1. Realm, 2. Dependency injection (Swinject), 3. Работа с платежными... • https://voronezh.hh.ru/vacancy/17552731

Slide 4

Slide 4 text

WWDC 2016: "Improving Existing Apps with Modern Best Practices" by Woody View Controller͸ྫ͑ͯݴ͏ͳΒ LEGOϒϩοΫͳͷ͞ɻ ಠཱͨ͠΋ͷΛ૊ΈཱͯͯશମΛ ߏ੒͢ΔΜͩʂ ؆୯ʹ૊Έཱ͍ͯͨͳΒ Dependency Injection Λ ࢖͏ͱϝνϟศརͩͥʂ https://developer.apple.com/videos/play/wwdc2016/213/ ɹat 21:45

Slide 5

Slide 5 text

ϝʔϧΞϓϦͷྫ http://devstreaming.apple.com/videos/wwdc/2016/213r47rtymgcyythv7w/213/213_improving_existing_apps_with_modern_best_practices.pdf pages 105, 106 ѱ͍ྫ ྑ͍ྫ ͢΂͕ͯ AppDelegateʹґଘ ࠷௿ݶඞཁͳ΋ͷʹ͚ͩґଘ

Slide 6

Slide 6 text

ѱ͍ྫ: AppDelegateʹґଘ class MyTableViewController: UITableViewController { override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return (UIApplication.sharedApplication().delegate as? AppDelegate)?.content?.count ?? 0 } } AppDelegateʹґଘ (͔͠΋γϯάϧτϯ)

Slide 7

Slide 7 text

ґଘΛProtocolʹ੾Γग़ͯ͠ ϦϑΝΫλϦϯά protocol ContentProvider { var content: Content { get } } class AppDelegate: UIResponder, UIApplicationDelegate, ContentProvider { private (set) var content = Content() } class MyTableViewController: UITableViewController { var contentProvider: ContentProvider? override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return contentProvider?.content.count ?? 0 } } ඞཁͳ෦෼͚ͩProtocolʹ੾Γग़͢ AppDelegateΛProtocolʹద߹ͤ͞Δ Protocolʹ͚ͩґଘ͠ɺ࣮ମͷΠϯελϯε͸֎͔Β౉ͯ͠΋Β͏

Slide 8

Slide 8 text

ଞʹ΋͍Ζ͍Ζґଘ͕͋Δ৔߹ protocol ViewManager { func presentViewControllerA() func presentViewControllerB() } extension AppDelegate: ViewManager { func presentViewControllerA() { ... } func presentViewControllerB() { ... } } class MyTableViewController: UITableViewController { var app: protocol? override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return app?.content.count ?? 0 } func doSomething() { app?.presentViewControllerA() } } ଞͷ෦෼΋άϧʔϓ͝ͱʹProtocolʹ੾Γग़͢ AppDelegateΛͦͷProtocolʹద߹ͤ͞Δ (extension͕ਪ঑) ෳ਺ͷProtocolΛ·ͱΊͨΠϯελϯεΛͱΔΑ͏ʹ͢Δ

Slide 9

Slide 9 text

຤୺ͷView Controller͸ඞཁͳ ProtocolͷΈͷܕͰड͚औΔ "QQ%FMFHBUF தؒ 7JFX$POUSPMMFS ຤୺ 7JFX$POUSPMMFS protocolܕ ͷϓϩύςΟΛఆٛ ContentProviderܕͷϓϩύςΟΛఆٛ (౉࣮͢ଶ͸AppDelegateͰ͍͍) (౉࣮͢ଶ͸AppDelegateͰ͍͍)

Slide 10

Slide 10 text

·ͱΊ • View Controller͸LEGOϒϩοΫ • ґଘੑ͕͖͍ͭͱࣗ༝ʹ૊ΈཱͯΒΕͳ͍ • Dependency Injection͕͋ΔͱLEGOϒϩοΫతʹͳΔ • Dependency InjectionΛద༻ͯ͠ϦϑΝΫλϦϯά