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

love-swift-vol8

 love-swift-vol8

2016年6月27日に開催された「集まれSwift好き!Swift愛好会 vol8」の資料です。#love_swift

B1ff34ce71b6f15fc9ee0361aedffa66?s=128

Kato Jun

June 29, 2016
Tweet

More Decks by Kato Jun

Other Decks in Programming

Transcript

  1. SwiftΛ࣮Ҋ݅Ͱ࢖ͬͯ ΞϓϦΛϦϦʔεͨ͠࿩ 2016.6.27 ू·ΕSwift޷͖ʂSwiftѪ޷ձ vol8 Kato Jun@Classmethod, Inc

  2. About Me • ໊લɿՃ౻ ५ • ձࣾɿΫϥεϝιου ϞόΠϧΞϓϦαʔϏε෦ॴଐ • ͓࢓ࣄɿiOSΞϓϦ։ൃ

    • ϒϩάɿhttp://dev.classmethod.jp/author/kato-jun/
  3. Agenda • SwiftͰΞϓϦΛ࡞Δ͜ͱʹͳͬͨܦҢ • ࢖ͬͨπʔϧ • SwiftͰϋϚͬͨͱ͜Ζ • Swift 3ରԠ

    • ·ͱΊ
  4. SwiftͰΞϓϦΛ࡞Δ ͜ͱʹͳͬͨܦҢ

  5. ࣌͸5ϲ݄΄Ͳલ…

  6. ͱ͋ΔडୗҊ݅Ͱ iOSΞϓϦΛ։ൃ͢Δ͜ͱʹ…

  7. ݴޠͷબ୒

  8. Obj-C or Swift ?

  9. Obj-C or Swift ? ϝϦοτ σϝϦοτ 0CK$ ɾʢݸਓతͳʣΞϓϦͷϦϦʔεܦݧ͋Γ ɾࣾ಺ʹϊ΢ϋ΢ɺ࣮੷͕๛෋ ɾϒϥέοτʢ<>ʣॻ͔ͳ͍ͱ͍͚ͳ͍

    ɾIͱN ɾ0QUJPOBMܕͱ͔΋ͪΖΜͳ͍ 4XJGU ɾ͜Ε͔Β࡞ΔͳΒײ ɾ؆ܿͳهड़ ɾ0QUJPOBMܕ͕࢖͑Δ ɾʢݸਓతͳʣΞϓϦͷϦϦʔεܦݧແ͠ ɾʢ0CK$ʹൺ΂ͯʣࣾ಺ʹϊ΢ϋ΢ɺ࣮ ੷͕গͳ͍
  10. ͳ͔ͳ͔λΠτͳεέδϡʔϧ…

  11. ϓϩϚω ʮݴޠͷ໰୊ͰϋϚΓͨ͘ ͳ͍ͷͰObj-C͔ͳʯ

  12. ࢲ SwiftͰେৎ෉Ͱ͠ΐ(´∀ʆ;)

  13. ͦͷޙ৭ʑͳਓ͔Β ॿݴΛड͚…

  14. Swift Ͱ։ൃ͢Δ͜ͱʹʂ

  15. ࢖ͬͨπʔϧ

  16. Tailor

  17. Tailor • Swift༻ͷ੩తίʔυղੳπʔϧ • ҎԼͷελΠϧΨΠυϥΠϯʹଇ͍ͬͯΔ͔ΛνΣοΫ ͯ͠ڭ͑ͯ͘ΕΔ • The Swift Programming

    LanguageʢAppleʣ • GitHub • Ray Wenderlich • Coursera
  18. Tailor • ࠷৽όʔδϣϯ͸0.10.0ʢ6/27ݱࡏʣ • Swift 2.2ʹରԠ • ΫϩεϓϥοτϑΥʔϜʢMac͸΋ͪΖΜLinux΍ WindowsͰ΋࢖͑Δʣ •

    MITϥΠηϯε • Xcodeʹ૊ΈࠐΜͰϏϧυ࣌ʹ࣮ߦ͢Δ͜ͱ͕Մೳ
  19. TailorΛXcodeʹ૊ΈࠐΉ • tailor --xcode <xcodeprojϑΝΠϧ΁ͷύε>

  20. Tailor͕νΣοΫͯ͘͠ΕΔ͜ͱ • ྫ͑͹ɺΫϥε໊ͷنଇ

  21. Tailor͕νΣοΫͯ͘͠ΕΔ͜ͱ • ྫ͑͹ɺηϛίϩϯ

  22. TailorΛಋೖͯ͠ྑ͔ͬͨ఺ • ਓྗͰνΣοΫ͠Α͏ͱ͢Δͱ࿙Ε͕ൃੜͦ͠͏ͳ෦ ෼ΛػցతʹνΣοΫͰ͖ͨ • ίʔυϨϏϡʔ࣌ʹϏδωεϩδοΫʹूதͰ͖ͨ • ಛʹηϛίϩϯ͸࠷ॳͷ͏ͪObjective-CͷบͰແҙࣝ Ͱ͚ͭͯ͠·͏͜ͱ͕ଟ͔͕ͬͨɺϏϧυ࣌ʹؾ෇͍ ͯमਖ਼͢Δ͜ͱ͕Ͱ͖ͨ

  23. TailorΛಋೖͯ͠Θ͔ͬͨ͜ͱ • ίʔυྔ͕૿͑ͯ͘ΔͱɺղੳʢϏϧυʣʹ͕͔͔࣌ؒ ΔΑ͏ʹͳͬͨ • ϓϩδΣΫτ࡞੒௚ޙ͸1ʙ2ඵ͕ͩͬͨɺ࠷ऴతʹ਺ ेඵ͔͔ΔΑ͏ʹͳͬͨ • Ϗϧυͷ౓ʹ࣮ߦ͢Δӡ༻͔ΒϦϦʔεͷ௚લʹ·ͱΊ ͯνΣοΫ͢Δӡ༻ʹมߋ

  24. SwiftͰϋϚͬͨͱ͜Ζ

  25. ZXingObjC • Objective-CͰ࡞ΒΕͨόʔίʔυϥΠϒϥϦ • https://github.com/TheLevelUp/ZXingObjC • όʔίʔυͷੜ੒ & όʔίʔυͷಡΈऔΓͰ࢖༻

  26. Կ͕໰୊͔ͩͬͨ • όʔίʔυੜ੒࣌ʹNSException͕ൃੜͨ͠ • ྫ͑͹ɺҎԼͷέʔεͰൃੜ • όʔίʔυܗࣜ͸EAN-13͕ͩɺ࣮ࡍͷܻ਺͕13Ͱ͸ ͳ͔ͬͨ࣌ • SwiftͰ͸NSExceptionΛΩϟονͰ͖ͳ͍ͷͰΫϥο

    γϡʢhttps://forums.developer.apple.com/thread/ 7582ʣ • Ϋϥογϡͤ͞ͳ͍Α͏ʹ͢Δඞཁ͕͋ͬͨ
  27. Ͳ͏ରॲ͔ͨ͠ • Obj-CͰNSExceptionΛNSErrorʹม׵ /4&YDFQUJPO͕ൃੜˠ/4&SSPSΛੜ੒

  28. Ͳ͏ରॲ͔ͨ͠ • ݁ՌɺSwiftͰ΋NSErrorͱͯ͠ΩϟονͰ͖ΔΑ͏ʹ /4&SSPSͱͯ͠ΩϟονͰ͖ΔΫϥογϡ͠ͳ͍

  29. ϋϚͬͨͱ͜Ζ͸͋ͬͨ΋ͷͷ ແࣄʹ༧ఆ௨ΓϦϦʔεͰ͖·ͨ͠ʂ

  30. Swift 3ରԠ

  31. ։ൃத͔ΒSwift 3Λҙࣝ • Xcode 7.3Ͱdeprecatedͳॻ͖ํΛ͍ͯ͠Δͱࢦఠͯ͘͠Εͨ • কདྷ࢖͑ͳ͘ͳΔදݱ͸։ൃத͔Β࢖Θͳ͍Α͏ʹͨ͠  JTEFQSFDBUFEJUXJMMCF SFNPWFEJO4XJGU

    $TUZMFGPSTUBUFNFOUJT EFQSFDBUFEBOEXJMMCFSFNPWFE JOBGVUVSFWFSTJPOPG4XJGU
  32. WWDC 2016 • What's New in Swift • Swiftͷมߋ఺ •

    ಺༰͸swift-evolutionͷproposal • Xcode 8 supports both Swift 2.3 and Swift 3 • ϚΠάϨʔγϣϯ࣌ʹ2.3ͱ3ͲͪΒΛ࢖༻͢Δ͔બ΂ Δ
  33. Swift 3ରԠͰӨڹ͕େ͖ͦ͏ͳͱ͜Ζ • SE-0046ɿؔ਺ͷୈҰҾ਺ʹ΋ݺͼग़࣌͠ʹϥϕϧ͕ඞ ཁʹͳͬͨ • SE-0069ɿ৽͍͠struct͕௥Ճ͞Εͨ • ex.) NSDate→Date

    • ex.) timeIntervalSinceDate→timeIntervalSince • SE-0006ɿenumͷcase͕lower camel caseʹ
  34. Xcode 8 betaͷϚΠάϨʔγϣϯΛࢼͯ͠Έͨ • Swift 2.2Ͱॻ͍ͨ؆୯ͳϓϩάϥϜ • Xcode 8 betaͰ͸ϏϧυΤϥʔ

    func func1(param1: Int, param2: Int) { } func func2() { func1(100, param2: 200) let date = NSDate() let interval = date.timeIntervalSinceDate(NSDate()) print(interval) } enum Fruit { case Apple case Banana case Orange } ͜ͷϓϩάϥϜʹ&EJU$POWFSU5P$VSSFOU4XJGU4ZOUBYʜΛ ࣮ߦ͢Δͱʜ 
  35. Use Swift 2.3Λબ୒ͨ͠৔߹ • ιʔείʔυͷมߋແ͠ͰϏϧυ͕௨ΔΑ͏ʹͳͬͨ

  36. Use Swift 3Λબ୒ͨ͠৔߹ • ؔ਺ఆٛͷୈҰҾ਺ϥϕϧʹʮ_ʯ͕௥Ճ͞Εͨʢݺͼग़͠ଆͷมߋ͸ͳ͠ʣ • ܕͷஔ׵ʢNSDate→Dateʣ • ؔ਺ͷஔ׵ʢtimeIntervalSinceDate→timeIntervalSinceʣ func

    func1(_ param1: Int, param2: Int) { } func func2() { func1(100, param2: 200) let date = Date() let interval = date.timeIntervalSince(Date()) print(interval) } enum Fruit { case apple case banana case orange } @͕௥Ճ͞Εͨ ݺͼग़͠ଆͷมߋ͸ͳ͠ ؔ਺ͷஔ׵ ܕͷஔ׵ DBTF͕MPXFSDBNFMDBTFʹ
  37. ·ͱΊ

  38. ·ͱΊ • SwiftࣗମʹϋϚͬͯࠔͬͨ͜ͱ͸ҙ֎ͱগͳ͔ͬͨ • Ή͠ΖOS΍ϑϨʔϜϫʔΫͷ஌ࣝͷํ͕େࣄ • ΋͏Obj-Cʹ͸໭Εͳ͍… Swift͸ॻ͖΍͍͢ʂ • TailorʹݶΒͣػցతʹνΣοΫͰ͖Δ͜ͱ͸πʔϧʹ೚ͤΑ͏

    • Obj-C੡ͷOSSΛSwiftͰ࢖͏ͱ͖͸NSExceptionʹؾΛ͚ͭΑ͏ • Swift 3ରԠ͸XcodeͷϚΠάϨʔλΛ࢖͑͹ػցతʹม׵ͯ͘͠ ΕΔ • ͋͘·ͰػցతͳͷͰϓϩδΣΫτಠࣗͷϧʔϧͳͲʹରԠͤ͞ Δ৔߹͸खಈͰͷରԠ͕ඞཁ
  39. ࠷ޙʹ

  40. Ϋϥεϝιου΋Swiftͷษڧձ΍ͬͯ·͢ʂʂ • AKIBA.swift • ݄1ϖʔεͰ։࠵ • @ΫϥεϝιουؠຊொΦϑΟε