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

大で小を兼ねるな

takasek
September 28, 2016

 大で小を兼ねるな

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

takasek

September 28, 2016
Tweet

More Decks by takasek

Other Decks in Programming

Transcript

  1. 2

  2. 3

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

    formatter = DateFormatter() formatter.dateFormat = "yyyy೥MM݄dd೔" return formatter.string(from: !) } 10
  4. ͜Μͳ;͏ʹม׵͢Δʁ extension Date { var shachikuDate: Date { if self.hour

    < 8 { //8࣌લͳΒ return (self.day - 1) //ࡢ೔ʹ͢Δ } else { return self } } } ※ͪΐͬͱٖࣅίʔυ 12
  5. ໰୊ᶃ 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. ໰୊ᶃ 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. ໰୊ᶃ ͳͥͳΒ 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. ໰୊ᶄ 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. ໰୊ᶄ 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. ໰୊ᶅ Ϣʔβʔೖྗ஋ΛɺαʔόʹૹΔ func didReceiveUserInput (year: Int, month: Int, day: Int)

    { let ! = Date( calendar: Caldendar.default, year: year, month: month, day: day ) API.send(!) } 19
  11. func didReceiveUserInput (year: Int, month: Int, day: Int) { let

    ! = Date( calendar: Caldendar.default, year: year, month: month, day: day ) API.send(!) } ɹ ! Ͳ͜ʹ໰୊͕…!? 23
  12. 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
  13. ͳΒɺ 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