Swift API Design
 learning from Cocoa API changes

Swift API Design
 learning from Cocoa API changes

Cocoa API changesから学ぶSwift API Designについて。

Swift API Guidelines: https://swift.org/documentation/api-design-guidelines/
iOS 10 API Diffs: https://developer.apple.com/library/archive/releasenotes/General/iOS10APIDiffs/Swift/UIKit.html

PR:
毎週火曜日 iOS Night を開催しています
https://github.com/wantedly/ios_night

88cc995ce5954b15c12ea14904258757?s=128

Kento Nagata

March 19, 2019
Tweet

Transcript

  1. ©2019 Wantedly, Inc. Swift API Design
 learning from Cocoa API

    changes try! Swift Pre Talks 2019 Mar 19, 2019 - Kento Nagata
  2. ©2018 Wantedly, Inc. ,FOUP/BHBUB 8BOUFEMZ *OD4PGUXBSF&OHJOFFS 8IBU*EPOPX ɾ(SPXUIPG8BOUFEMZ7JTJU 
 &OHJOFFSJOH

    ɾ3BJMTZFBST ɾJ044XJGUZFBS/FX
  3. ©2019 Wantedly, Inc. Cocoa APIͷมߋ͔ΒAPI DesignΛཧղ͢Δ ࠓ೔࿩͢͜ͱ

  4. ©2019 Wantedly, Inc. TXJGUPSHʹ͋Δ
 l"1*%FTJHO(VJEFMJOFTz
 ΛಡΜͩ͜ͱ͕͋Δํ͸
 ͨ͘͞Μ͍Δͱࢥ͍·͢

  5. ©2019 Wantedly, Inc. l"1*%FTJHO(VJEFMJOFTz
 ͸ඇৗʹॏཁ

  6. ©2019 Wantedly, Inc. ͜ͷΑ͏ͳࢦ਑΍׳श͸
 ࣮ࡍͷྫΛݟͨํ͕ૣ͍

  7. ©2019 Wantedly, Inc. ΋ͬͱ΋࣮ྫͱͯ͠༏Ε͍ͯΔͷ͕ɺ
 J044%, $PDPBͰ͋Γ "QQMFͷίʔυͰ͢

  8. ©2019 Wantedly, Inc. ͦͷલʹl"1*%FJHO(VJEFMJOFTzͷ
 ಺༰ͷུ֓ʹ͍͓ͭͯ͞Β͍͠·͢

  9. ©2019 Wantedly, Inc.  'VOEBNFOUBMT  /BNJOH w 1SPNPUF$MFBS6TBHF w

    4USJWFGPS'MVFOU6TBHF w 6TF5FSNJOPMPHZ8FMM  $POWFOUJPOT w (FOFSBM$POWFOUJPOT w 1BSBNFUFST w "SHVNFOU-BCFMT  4QFDJBM *OTUSVDUJPOT "1*%FTJHO(VJEFMJOFT IUUQTTXJGUPSHEPDVNFOUBUJPOBQJEFTJHOHVJEFMJOFT
  10. ©2019 Wantedly, Inc.  'VOEBNFOUBMT  /BNJOH w 1SPNPUF$MFBS6TBHF w

    4USJWFGPS'MVFOU6TBHF w 6TF5FSNJOPMPHZ8FMM  $POWFOUJPOT w (FOFSBM$POWFOUJPOT w 1BSBNFUFST w "SHVNFOU-BCFMT  4QFDJBM *OTUSVDUJPOT "1*%FTJHO(VJEFMJOFT IUUQTTXJGUPSHEPDVNFOUBUJPOBQJEFTJHOHVJEFMJOFT Ұ൪ॏཁͳࢦ਑͕ॻ͔Ε͍ͯΔɻ
  11. ©2019 Wantedly, Inc.  'VOEBNFOUBMT  /BNJOH w 1SPNPUF$MFBS6TBHF w

    4USJWFGPS'MVFOU6TBHF w 6TF5FSNJOPMPHZ8FMM  $POWFOUJPOT w (FOFSBM$POWFOUJPOT w 1BSBNFUFST w "SHVNFOU-BCFMT  4QFDJBM *OTUSVDUJPOT "1*%FTJHO(VJEFMJOFT IUUQTTXJGUPSHEPDVNFOUBUJPOBQJEFTJHOHVJEFMJOFT ໌֬͞Λ࣮ݱ͢ΔͨΊͷϧʔϧɺ
 ΑΓ۩ମతͳύλʔϯɺޠኮͷબͼํ
  12. ©2019 Wantedly, Inc.  'VOEBNFOUBMT  /BNJOH w 1SPNPUF$MFBS6TBHF w

    4USJWFGPS'MVFOU6TBHF w 6TF5FSNJOPMPHZ8FMM  $POWFOUJPOT w (FOFSBM$POWFOUJPOT w 1BSBNFUFST w "SHVNFOU-BCFMT  4QFDJBM *OTUSVDUJPOT "1*%FTJHO(VJEFMJOFT IUUQTTXJGUPSHEPDVNFOUBUJPOBQJEFTJHOHVJEFMJOFT ΑΓ۩ମతͳέʔεͰͷ׳शɺ
 ύϥϝʔλ΍Ҿ਺ϥϕϧͷॻ͖ํ
  13. ©2019 Wantedly, Inc.  'VOEBNFOUBMT  /BNJOH w 1SPNPUF$MFBS6TBHF w

    4USJWFGPS'MVFOU6TBHF w 6TF5FSNJOPMPHZ8FMM  $POWFOUJPOT w (FOFSBM$POWFOUJPOT w 1BSBNFUFST w "SHVNFOU-BCFMT  4QFDJBM *OTUSVDUJPOT "1*%FTJHO(VJEFMJOFT IUUQTTXJGUPSHEPDVNFOUBUJPOBQJEFTJHOHVJEFMJOFT ͦͷଞɺಛघͳέʔεʹ͍ͭͯ
  14. ©2019 Wantedly, Inc.  'VOEBNFOUBMT  /BNJOH w 1SPNPUF$MFBS6TBHF w

    4USJWFGPS'MVFOU6TBHF w 6TF5FSNJOPMPHZ8FMM  $POWFOUJPOT w (FOFSBM$POWFOUJPOT w 1BSBNFUFST w "SHVNFOU-BCFMT  4QFDJBM *OTUSVDUJPOT "1*%FTJHO(VJEFMJOFT IUUQTTXJGUPSHEPDVNFOUBUJPOBQJEFTJHOHVJEFMJOFT ࠓ೔औΓ্͛Δ෦෼
  15. ©2019 Wantedly, Inc. ϧʔϧͷదԠྫΛݟΔ J04ͰͷมߋΛओʹݟ͍ͯ͘

  16. ©2019 Wantedly, Inc. ඞཁͷͳ͍ݴ༿Λ࡟Δ /BNJOH1SPNPUF$MFBS6TBHFl0NJUOFFEMFTTXPSETz

  17. ©2019 Wantedly, Inc. UIActivity.perform #FGPSF - iOS 9 Activity()

  18. ©2019 Wantedly, Inc. UIActivity.perform() "GUFS iOS 10 -

  19. ©2019 Wantedly, Inc. UIActivity.perform() "GUFS UIActivity.performActivity() #FGPSF activityΛperform͢Δͷ͸ϨγʔόΛݟΕ͹ࣗ໌ - iOS

    9 iOS 10 -
  20. ©2019 Wantedly, Inc. UIResponder.pressesBegan(_: Set<UIPress>, withEvent: UIPressesEvent?) #FGPSF - iOS

    9
  21. ©2019 Wantedly, Inc. UIResponder.pressesBegan(_: Set<UIPress>, with: UIPressesEvent?) "GUFS iOS 10

    -
  22. ©2019 Wantedly, Inc. UIResponder.pressesBegan(_: Set<UIPress>, with: UIPressesEvent?) "GUFS UIResponder.pressesBegan(_: Set<UIPress>,

    withEvent: UIPressesEvent?) #FGPSF ܕΛݟΕ͹Θ͔Δݴ༿ iOS 10 - - iOS 9
  23. ©2019 Wantedly, Inc. ܕ৘ใ͕ऑ͍΋ͷΛิ׬͢Δ /BNJOH1SPNPUF$MFBS6TBHFl$PNQFOTBUFGPSXFBLUZQFJOGPSNBUJPOz

  24. ©2019 Wantedly, Inc. UITableView.rectForSection(_ section: Int) -> CGRect #FGPSF -

    iOS 9
  25. ©2019 Wantedly, Inc. UITableView.rect(forSection: Int) -> CGRect "GUFS iOS 10

    -
  26. ©2019 Wantedly, Inc. UITableView.rect(forSection: Int) -> CGRect "GUFS UITableView.rectForSection(_ section:

    Int) -> CGRect #FGPSF ܕ͚ͩͰ͸໾ׂ͸෼͔Βͳ͍ iOS 10 - - iOS 9
  27. ©2019 Wantedly, Inc. ࠷ॳͷҾ਺͕લஔࢺ۟ͷҰ෦Λͳ͢৔߹͸ɺ
 ͦΕʹҾ਺ϥϕϧΛ͚ͭΔ $POWFOUJPOT1BSBNFUFST l8IFOUIFpSTUBSHVNFOUGPSNTQBSUPGBQSFQPTJUJPOBMQISBTF  HJWFJUBOBSHVNFOUMBCFMz

  28. ©2019 Wantedly, Inc. UIView.point #FGPSF - iOS 9 Inside(_: CGPoint,

    withEvent: UIEvent?) -> Bool
  29. ©2019 Wantedly, Inc. "GUFS UIView.point(inside: CGPoint, with: UIEvent?) -> Bool

    iOS 10 -
  30. ©2019 Wantedly, Inc. "GUFS UIView.point(inside: CGPoint, with: UIEvent?) -> Bool

    UIView.pointInside(_: CGPoint, withEvent: UIEvent?) -> Bool #FGPSF લஔࢺ۟ΛϥϕϧʹؚΊΔ iOS 10 - - iOS 9
  31. ©2019 Wantedly, Inc. UIViewController.willMove(toParentViewController: UIViewController?) "GUFS UIViewController.willMoveToParentViewController(_: UIViewController?) #FGPSF ໾ׂ͕͸͖ͬΓ͠ͳ͍৔߹͸໨తޠΛ໌ه

  32. ©2019 Wantedly, Inc. ҰํͰɺ࠷ॳͷҾ਺͕จ๏తͳϑϨʔζʹ
 ؚ·ΕΔ৔߹͸ɺϥϕϧΛআ͘ $POWFOUJPOT1BSBNFUFST l0UIFSXJTF JGUIFpSTUBSHVNFOUGPSNTQBSUPGBHSBNNBUJDBMQISBTF PNJUJUTMBCFMz

  33. ©2019 Wantedly, Inc. UIView.sendSubviewToBack(_: UIView) #FGPSF - iOS 9

  34. ©2019 Wantedly, Inc. UIView.sendSubview(toBack: UIView) "GUFS iOS 10 -

  35. ©2019 Wantedly, Inc. UIView.sendSubview(toBack: UIView) "GUFS UIView.sendSubviewToBack(_: UIView) #FGPSF toBack͸લஔࢺ͚۟ͩͲɺ


    Ҿ਺͸toBackͷ໨తޠͰ͸ͳ͍ iOS 10 - ? - iOS 9
  36. ©2019 Wantedly, Inc. UIView.sendSubviewToBack(_: UIView) /PX ࠷ॳͷҾ਺͸sendͷ໨తޠsubviewͱͯ͠
 ϝιου໊ʹؚ·Ε͍ͯΔ iOS 12

    ಉ͡΋ͷ
  37. ©2019 Wantedly, Inc. ·ͱΊ

  38. ©2019 Wantedly, Inc.  "1*ͷσβΠϯʹ͍ͭͯ໎ͬͨ࣌ɺ
 ·ͣ͸(VJEFMJOF  $PDPB΍ελϯμʔυϥΠϒϥϦ͸࠷ߴͷ͓खຊ ·ͱΊ

  39. ©2019 Wantedly, Inc.  "1*ͷσβΠϯʹ͍ͭͯ໎ͬͨ࣌ɺ
 ·ͣ͸(VJEFMJOF  $PDPB΍ελϯμʔυϥΠϒϥϦ͸࠷ߴͷ͓खຊ ·ͱΊ

  40. ©2019 Wantedly, Inc. "QQFOEJY

  41. ©2019 Wantedly, Inc. "1*%FTJHO(VJEFMJOFTIUUQTTXJGUPSH EPDVNFOUBUJPOBQJEFTJHOHVJEFMJOFT J04"1*%J⒎TIUUQTEFWFMPQFSBQQMFDPNMJCSBSZ BSDIJWFSFMFBTFOPUFT(FOFSBMJ04"1*%J⒎T4XJGU6*,JUIUNM "QQFOEJY

  42. ©2019 Wantedly, Inc. ຖिՐ༵೔J04/JHIUΛ։࠵͍ͯ͠·͢ 13 IUUQTHJUIVCDPNXBOUFEMZJPT@OJHIU JPT@OJHIU ւ֎ͷϒϩάͳͲ࠷৽ͷ৘ใΛΧδϡΞϧʹڞ༗͋͠͏ձͰ͢ɻ