大で小を兼ねるな

704056da9a4c4e075ad14479beaebab7?s=47 takasek
September 28, 2016

 大で小を兼ねるな

potatotips #33 (iOS/Android開発Tips共有会)
http://potatotips.connpass.com/event/38557/
の発表資料です。

704056da9a4c4e075ad14479beaebab7?s=128

takasek

September 28, 2016
Tweet

Transcript

  1. 2.

    2

  2. 3.

    3

  3. 10.

    ShachikuDateͷจࣈྻදݱΛಘΔ func shachikuDateDescription (_ !: Date) -> String { let

    formatter = DateFormatter() formatter.dateFormat = "yyyy೥MM݄dd೔" return formatter.string(from: !) } 10
  4. 12.

    ͜Μͳ;͏ʹม׵͢Δʁ extension Date { var shachikuDate: Date { if self.hour

    < 8 { //8࣌લͳΒ return (self.day - 1) //ࡢ೔ʹ͢Δ } else { return self } } } ※ͪΐͬͱٖࣅίʔυ 12
  5. 13.

    ໰୊ᶃ let !1 = parseDate("2016-09-27 08:00:00") let !2 = parseDate("2016-09-28

    07:59:58") !1.shachikuDate < !2.shachikuDate ౰વtrueΛظ଴͠·͢ΑͶʁɹͰ΋… 13
  6. 14.

    ໰୊ᶃ let !1 = parseDate("2016-09-27 08:00:00") let !2 = parseDate("2016-09-28

    07:59:58") !1.shachikuDate < !2.shachikuDate // false" 14
  7. 15.

    ໰୊ᶃ ͳͥͳΒ let !1 = parseDate("2016-09-27 08:00:00") let !2 =

    parseDate("2016-09-28 07:59:58") !1.shachikuDate // "2016-09-27 08:00:00" "มԽͯ͠ͳ͍ !2.shachikuDate // "2016-09-27 07:59:58" "Ұ೔ḪͬͯΔ 15
  8. 16.

    ໰୊ᶄ func printHoge(with !: Date) { printFuga(!.shachikuDate) } func printFuga(with

    !: Date) { print(!.shachikuDate) } let ! = parseDate("2016-09-28 07:59:58") printHoge(with: !) // "2016೥09݄26೔" ࡢ೔(9/27)ͷ೔෇Λظ଴͍ͯ͠Δͷʹɺ Ұࡢ೔(9/26)ʹͳ͍ͬͯΔ… 16
  9. 17.

    ໰୊ᶄ func printHoge(with !: Date) { printFuga(!.shachikuDate) } func printFuga(with

    !: Date) { print(!.shachikuDate) } ɹ Α͘ಡΉͱɺ 1. printHoge(with:) Ͱલ೔ͷDateʹม׵ 2. printHoge(with:) ͔Β printFuga(with:) ΛݺͿ 4 printFuga(with:) Ͱߋʹલ೔ͷDateʹม׵ 17
  10. 19.

    ໰୊ᶅ Ϣʔβʔೖྗ஋ΛɺαʔόʹૹΔ func didReceiveUserInput (year: Int, month: Int, day: Int)

    { let ! = Date( calendar: Caldendar.default, year: year, month: month, day: day ) API.send(!) } 19
  11. 22.
  12. 23.

    func didReceiveUserInput (year: Int, month: Int, day: Int) { let

    ! = Date( calendar: Caldendar.default, year: year, month: month, day: day ) API.send(!) } ɹ ! Ͳ͜ʹ໰୊͕…!? 23
  13. 24.

    func didReceiveUserInput (year: Int, month: Int, day: Int) { let

    ! = Date( calendar: Caldendar.default, //"࣮͸࿨ྐྵઃఆ#ͯͨ͠!!! year: year, //$2016 month: month, day: day ) API.send(!) } ࿨ྐྵઃఆͳͷͰ ! = ฏ੒2016೥ = 1988 + 2016 = ੢ྐྵ4004೥ ͱ͍͏Φν 24
  14. 31.

    ͳΒɺ struct YMD { let year: Int let month: Int

    let day: Int var description: String { return "\(year)೥\(month)݄\(day)೔" } } let ! = YMD(year: 2016, month: 9, day: 28) 31
  15. 34.