Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PotatoTips_73.pdf

u5-03
March 27, 2021

 PotatoTips_73.pdf

u5-03

March 27, 2021
Tweet

More Decks by u5-03

Other Decks in Technology

Transcript

  1. 3&"%.& w /BNFਿࢁ༏ޛ:VHP4VHJZBNB w "HFࡀ w 'SPNਆಸ઒ݝ౻୔ࢢ w +PC4)08300.גࣜձࣾ d

     w )PCCZྉཧɺΞχϝɺࣗసंɺςχε w 2VBMJ fi DBUJPOڭһ໔ڐ தֶߴ౳ֶߍࣾձՊશൠ
  2. 1. Dependency InjectionΛ࢖ͬͯɺ௨৴ॲཧͷAPI ༻/Mock༻ͷClassΛ੾Γସ͑ΒΕΔΑ͏ʹ͢Δɻ • API઀ଓ༻ͷΫϥεͱMock༻ͷclassΛDIΛ࢖ͬͯɺ੾Γସ͑ΒΕΔΑ͏ʹ͢Δ • σϞΞϓϦͰ͸ɺDIContainerͱͯ͠DependenciesΛϕʔεͯ͠ɺҎԼͷΑ͏ʹ ࢖ͬͯ·͢ɻ •

    @InjectͱܕΛ͚ͭΔͱɺDIContainerʹઃఆͨ͠ΠϯελϯεΛࢀরͰ͖Δ • ࢀরΛ͍࣋ͬͯΔ͚ͩͳͷͰɺDebugMenuͳͲ͔ΒΠϯελϯεΛ੾Γସ͑Δ͜ ͱ͕Ͱ͖Δɻ @Inject private var mockService: MockProtocol
  3. 3. MockͷClass͸ઃఆͨ͠MockTypeʹԠͨ͡ ஋Λฦ͢Α͏ʹ͢Δɻ • બ୒ͨ͠MockTypeʹԠͯ͡ɺϨεϙϯεΛ੾Γସ͑Δ switch mockType { case .randomList:

    let list = [Int](0...Int.random(in: 1...100)) .map({ _ in ColorModel(text: .random(), color: .random) }) completion(.success(list)) case .single: completion(.success([.init(text: .random(), color: .random)])) case .empty: completion(.success([])) case .error: completion(.failure(MockError.mockError(message: "This is Error(Mock)”))) …… }