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

Swift coding Strategy

Swift coding Strategy

AKIBA.swift 1周年記念での発表スライドです
テックな内容は皆無です

https://classmethod.connpass.com/event/53603/

Takaaki Tanaka

April 17, 2017
Tweet

More Decks by Takaaki Tanaka

Other Decks in Technology

Transcript

  1. • ాத ޹໌ (Takaaki Tanaka) • Ϋϥεϝιουגࣜձࣾ • ϞόΠϧόοΫΤϯυ •

    @kongmingtrap • Swift / Objective-C / Scala / JavaScript … • GyazSquare / GitHub
  2. Strategy Pattern // MARK: - Interface public protocol TodoRepository {

    func get(_ handler: @escaping (Result<[TodoEntity]>) -> Void) } // MARK: - Implementation final class TodoRepositoryImpl: TodoRepository { private let dataStore: TodoDataStore public init(dataStore: TodoDataStore) { self.dataStore = dataStore } func get(_ handler: @escaping (Result<[TodoEntity]>) -> Void) { dataStore.get(with: ["filter": "all"]).onSuccess { entities in let result = Result<[TodoEntity]>.success(entities) handler(result) }.onFailure { error in let result = Result<[TodoEntity]>.failure(error) handler(result) } } }
  3. Strategy Pattern typealias TodoListComplitionHandler = ([TodoModel]?) -> Void // MARK:

    - Interface protocol TodoListUseCase { func fetchTodos(_ complite: TodoListComplitionHandler?) } // MARK: - Implementation struct TodoListUseCaseImpl: TodoListUseCase { private let todoRepository: TodoRepository public init(todoRepository: TodoRepository) { self.todoRepository = todoRepository } public func fetchTodos(_ compliton: TodoListComplitionHandler?) { todoRepository.get { result in switch result { case .success(let value): let todoModels = try! TodoTranslator().translate(value) compliton?(todoModels) case .failure(let error): print(error) compliton?(nil) } } } }
  4.   USZ4XJGUৼΓฦΓษڧձ  Ր  4XJGUͱ0CKFDUJWF$ͱͷจ๏ൺֱ  Ր 

    88%$৘ใڞ༗ձ  ۚ  4XJGU-5େձʂ  Ր  εϖγϟϧίϥϘʂʂ  ݄  ϑϦʔτʔʔΫʂʂ  Ր  GBTUMBOFϋϯζΦϯ  Ր  ϑϦʔτʔʔΫʂʂ  Ր  લ೔ʹࠂ஌͢ΔษڧձɺͦΕ͕",*#"TXJGU  Ր  ϑϦʔτʔʔΫʂʂ  Ր  ,ZPCBTIJTXJGUY",*#"TXJGU߹ಉษڧձ  ਫ  ",*#"TXJGUº4XJGUѪ޷ձWPM  ݄  ",*#"TXJGUҰप೥ه೦ษڧձʂ  ݄ ։࠵ཤྺ
  5.   USZ4XJGUৼΓฦΓษڧձ  Ր  4XJGUͱ0CKFDUJWF$ͱͷจ๏ൺֱ  Ր 

    88%$৘ใڞ༗ձ  ۚ  4XJGU-5େձʂ  Ր  εϖγϟϧίϥϘʂʂ  ݄  ϑϦʔτʔʔΫʂʂ  Ր  GBTUMBOFϋϯζΦϯ  Ր  ϑϦʔτʔʔΫʂʂ  Ր  લ೔ʹࠂ஌͢ΔษڧձɺͦΕ͕",*#"TXJGU  Ր  ϑϦʔτʔʔΫʂʂ  Ր  ,ZPCBTIJTXJGUY",*#"TXJGU߹ಉษڧձ  ਫ  ",*#"TXJGUº4XJGUѪ޷ձWPM  ݄  ",*#"TXJGUҰप೥ه೦ษڧձʂ  ݄ ։࠵ཤྺ
  6.   USZ4XJGUৼΓฦΓษڧձ  Ր  4XJGUͱ0CKFDUJWF$ͱͷจ๏ൺֱ  Ր 

    88%$৘ใڞ༗ձ  ۚ  4XJGU-5େձʂ  Ր  εϖγϟϧίϥϘʂʂ  ݄  ϑϦʔτʔʔΫʂʂ  Ր  GBTUMBOFϋϯζΦϯ  Ր  ϑϦʔτʔʔΫʂʂ  Ր  લ೔ʹࠂ஌͢ΔษڧձɺͦΕ͕",*#"TXJGU  Ր  ϑϦʔτʔʔΫʂʂ  Ր  ,ZPCBTIJTXJGUY",*#"TXJGU߹ಉษڧձ  ਫ  ",*#"TXJGUº4XJGUѪ޷ձWPM  ݄  ",*#"TXJGUҰप೥ه೦ษڧձʂ  ݄ ςʔϚ͕ܾ·Βͳ͔ͬͨճ
  7.   USZ4XJGUৼΓฦΓษڧձ  Ր  4XJGUͱ0CKFDUJWF$ͱͷจ๏ൺֱ  Ր 

    88%$৘ใڞ༗ձ  ۚ  4XJGU-5େձʂ  Ր  εϖγϟϧίϥϘʂʂ  ݄  ϑϦʔτʔʔΫʂʂ  Ր  GBTUMBOFϋϯζΦϯ  Ր  ϑϦʔτʔʔΫʂʂ  Ր  લ೔ʹࠂ஌͢ΔษڧձɺͦΕ͕",*#"TXJGU  Ր  ϑϦʔτʔʔΫʂʂ  Ր  ,ZPCBTIJTXJGUY",*#"TXJGU߹ಉษڧձ  ਫ  ",*#"TXJGUº4XJGUѪ޷ձWPM  ݄  ",*#"TXJGUҰप೥ه೦ษڧձʂ  ݄ ϗʔϜͰ։࠵͠ͳ͔ͬͨճɹ#AKIBA #ͱ͸
  8.   USZ4XJGUৼΓฦΓษڧձ  Ր  4XJGUͱ0CKFDUJWF$ͱͷจ๏ൺֱ  Ր 

    88%$৘ใڞ༗ձ  ۚ  4XJGU-5େձʂ  Ր  εϖγϟϧίϥϘʂʂ  ݄  ϑϦʔτʔʔΫʂʂ  Ր  GBTUMBOFϋϯζΦϯ  Ր  ϑϦʔτʔʔΫʂʂ  Ր  લ೔ʹࠂ஌͢ΔษڧձɺͦΕ͕",*#"TXJGU  Ր  ϑϦʔτʔʔΫʂʂ  Ր  ,ZPCBTIJTXJGUY",*#"TXJGU߹ಉษڧձ  ਫ  ",*#"TXJGUº4XJGUѪ޷ձWPM  ݄  ",*#"TXJGUҰप೥ه೦ษڧձʂ  ݄ ͦ΋ͦ΋ษڧձ͡Όແ͍