티스토리 뷰


2018-01-08 Today To Do List

Well done is better than well said.<br>기록은 기억을 지배한다.

  • Vending App Step5 PR - Contorller와 Model과의 관계를 관찰자 패턴을 적용하여 느슨하게 만들기.

  • 관찰자 패턴 공부

  • HIG Visual Design 발표

  • 면접 준비를 위해 꼼꼼히 평소에 공부하자

2018-01-09 Today To Do List

Well done is better than well said.<br>기록은 기억을 지배한다.

2018-01-10 Today To Do List

Well done is better than well said.f<br>기록은 기억을 지배한다.

  • Vending App Step6 PR

  • Clean Code 2장까지.

2018-01-11 Today To Do List

Well done is better than well said.<br>기록은 기억을 지배한다.

  • Vending App Step6 PR

  • Vending App Refacto

  • Clean Code 3장까지.

  • 멜트다운 이란? 읽고공부

2018-01-12 Today To Do List

Well done is better than well said.<br>기록은 기억을 지배한다.

  • Vending App Step6 PR

  • Vending App Refacto

  • Clean Code 3장까지.

private func match(buttons: [UIButton], sequence beverages: [Beverage]) -> [UIButton: Beverage] {
   var matchedButton = [UIButton: Beverage]()
   for index in 0..<buttons.count {
       matchedButton[buttons[index]] = beverages[index]
   }
   return matchedButton
}

private func match(sequence beverages: [Beverage], labels: [UILabel]) -> [Beverage: UILabel] {
   var beverageLabel = [Beverage: UILabel]()
   for index in 0..<labels.count {
       beverageLabel[beverages[index]] = labels[index]
   }
   return beverageLabel
}

위의 두 메소드를 하나로 묶기위해 정말 여러날 고민했었다. 처음에 딱 떠오른게 제네릭이었는데, 리턴타입이 달라서 쓸 수가 없다고 생각했다. 하지만 자세히보면 위의 match의 매게변수의 입력에따라, 리턴값의 딕셔너리의 키와 밸류가 달라지는 것을 볼 수 있다. 왜 이걸 처음엔 보지 못했을까? (JK의 도움으로 보였다.)


   private func matches<T, U>(indexList: [T], valueList: [U]) -> [T: U] {
       var matchedList = [T: U]()
       for index in 0..<indexList.count {
           matchedList[indexList[index]] = valueList[index]
       }
       return matchedList
   }


Comments