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

大で小を兼ねるな

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. େͰখΛ݉ͶΔͳ by takasek 2016/9/28 potatotips 33 1

  2. 2

  3. 3

  4. օ͞Μ͸ ೔෇Λ؅ཧ͢Δͱ͖ɺ ͲͷܕΛ࢖͍·͔͢ʁ 4

  5. NSDate? 5

  6. ΋ͱ͍ Date? 6

  7. ͋ͳͨͷΞϓϦͷ ೔෇࢓༷ 4 Ұ೔͸24࣌ؒ 7

  8. ͋ͳͨͷΞϓϦͷ ೔෇࢓༷ 4 Ұ೔͸24࣌ؒ 4 ೔෇͕มΘΔͷ͸ɺே8࣌ 8

  9. ͋ͳͨͷΞϓϦͷ ೔෇࢓༷ 4 Ұ೔͸24࣌ؒ 4 ೔෇͕มΘΔͷ͸ɺே8࣌ ɹ ※͜ͷ೔෇Λɺ ɹ௨ৗͷ೔෇ͱ۠ผ͢ΔͨΊʹɺ ɹShachikuDate

    ͱݺͼ·͢ 9
  10. ShachikuDateͷจࣈྻදݱΛಘΔ func shachikuDateDescription (_ !: Date) -> String { let

    formatter = DateFormatter() formatter.dateFormat = "yyyy೥MM݄dd೔" return formatter.string(from: !) } 10
  11. ShachikuDateΛ࢖͍͍ͨ let ! = parseDate("2016-09-28 07:59:58") //"8࣌લͳͷͰɺ shachikuDateDescription(!) //2016೥09݄27೔ #ͱද͍ࣔͨ͠

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

    < 8 { //8࣌લͳΒ return (self.day - 1) //ࡢ೔ʹ͢Δ } else { return self } } } ※ͪΐͬͱٖࣅίʔυ 12
  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
  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
  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
  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
  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
  18. !"#$%!"$% όάʹؾ෇͚Δ ؾ͕͠ͳ͍… %$"!%$#"! 18

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

    { let ! = Date( calendar: Caldendar.default, year: year, month: month, day: day ) API.send(!) } 19
  20. !ʮͳ͋ʯ 20

  21. !ʮDBʹ 4004೥ͱ͔ ೖͬͯΔΜ͚ͩͲʯ 21

  22. !? 22

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

    ! = Date( calendar: Caldendar.default, year: year, month: month, day: day ) API.send(!) } ɹ ! Ͳ͜ʹ໰୊͕…!? 23
  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
  25. ॾѱͷࠜݯ Dateͱ͍͏ܕΛ ࢖͍ճ͍ͯ͠Δ 25

  26. Dateܕ͸ศར 26

  27. λΠϜκʔϯͷҧ͍΋ ྐྵ๏ͷҧ͍΋ શ෦ٵऩͯ͘͠ΕΔ 27

  28. Ͱ΋ ࣌ࠁͷࡉ੍͔͍ޚͬͯ ࠓɺඞཁʁ 28

  29. ࠓɺྐྵ๏ͬͯඞཁʁ 29

  30. ShachikuDate͕΄͍͠ͷ͸ ೔෇! ͚ͩ 30

  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
  32. γϯ ϓϧ 32

  33. όάͷೖΓࠐΈΑ͏͕ͳ͍ 33

  34. !✨ 34

  35. ಉ͜͡ͱ͸ ΤϯδχΞϦϯάͷ ༷ʑͳঢ়گͰ ݴ͑ͯɺ 35

  36. ྫ1 ☑ จষΛද͍ࣔͨ͠ ☑ Ұఆͷߴ͞Λ௒͑ͨΒεΫϩʔϧ͍ͤͨ͞ ! ͩͬͨΒUITextViewͰ͠ΐ͏ 36

  37. ݁Ռ1 ! จষྖҬͷϚʔδϯͷ੍ޚͭΒ͍… จষྖҬͷheight͕͏·͘औΕͳ͍… …ਏ͍… 37

  38. !NSLayoutManager !NSTextStorage !NSTextContainer !etc... 38

  39. UITextViewͷ ಺෦ߏ଄͸ ҙ֎ͱຐڥ 39

  40. εΫϩʔϧͰ͖ΔLabel͕ ཉ͍͚ͩ͠ͳΒɺ UITextView͸ ΦʔόʔεϖοΫ 40

  41. ݁ہ1 ! UILabel Λ UIScrollView ʹೖΕΔ࣮૷Ͱ ͘͢͝γϯϓϧʹղܾͰ͖ͨ… ʢίʔυ1ߦ΋ॻ͔ͣɺ ɹInterfaceBuilderͰ׬݁Ͱ͖ΔϨϕϧʣ 41

  42. ྫ2 ! ◦◦ػೳΛ࢖͍͍ͨͷͰ ͋ͷϥΠϒϥϦೖΕΑ͏ͬͱʂ 42

  43. ݁Ռ2 ! ͋ͷϥΠϒϥϦͷ××ػೳʢผʹཁΒͳ͍ʣ ͕ ґଘ͢ΔผͷϥΠϒϥϦͷ͍ͤͰ Xcode8ରԠ͕ਐ·ͳ͍… ! Ͱ΋୤ϥΠϒϥϦ͸ ࠓߋແཧ… 43

  44. ͓Θ͔ΓͩΖ͏͔ ػೳ͕ଟ͍ ʹ ᠘͕ଟ͍ 44

  45. େ͕খΛ݉ͶΔͱ ൵͠Έ͕ੜ·ΕΔ 45

  46. ͱ͍͏Θ͚Ͱ 46

  47. େࣄͳ͜ͱͳͷͰ ΋͏Ұ౓ݴ͍·͢ 47

  48. େͰ খΛ ݉ͶΔͳ 48

  49. ɹҎ্ɻ 49

  50. see also: UNIX఩ֶ - Wikipedia 50