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

ざっくりわかるSwift

 ざっくりわかるSwift

Bf65cc9bdf26321a7579ddca7930cd10?s=128

Shigure Shimotori

July 19, 2017
Tweet

More Decks by Shigure Shimotori

Other Decks in Programming

Transcript

  1. ͬ͘͟ΓΘ͔ΔSwift TokyoTech LT #2 @S_Shimotori

  2. ୭ʁ • @S_Shimotori (@S_Shimotori_pub) • ৘ऑΤֶܥM2 • DroidKaigiӡӦελοϑ • Swift΍PythonΛॻ͍͓ͯۚΛ໯͏͓࢓ࣄ

  3. DroidKaigi2018 ։࠵ܾఆʂ 2018೥2݄8-9೔@ϕϧαʔϧ৽॓άϥϯυ https://droidkaigi.github.io/2018/

  4. AndroidͱiOSͷ؀ڥͷҧ͍ • Android • ॳճ͚ͩొ࿥ྉΛ෷͑͹OK • ೔ຊAndroidͷձ͕͋Δɺֶੜ෦΋͋Δ • ࠓKotlin͕೤͍ʂ •

    iOS • ຖ೥͓෍ࢪ͕ඞཁ • ͦΜͳձ͚͋ͬͨͬ • ·ͨSwift4ʹॻ͖׵͑Δ࡞ۀ͕͸͡·Δ͓…
  5. ϞόΠϧͷ࿩͸Ҏ্ʂ

  6. ຊ୊

  7. ͓඼ॻ͖ • Swiftͷจ๏ͷ֓ཁ • Swift͕࢖͑Δ৔ॴ • CϥΠϒϥϦͷݺͼग़͠ • Swiftʹ͍ͭͯ΋ͬͱ஌Γ͍ͨͱ͖͸

  8. ͓඼ॻ͖ • Swiftͷจ๏ͷ֓ཁ • Swift͕࢖͑Δ৔ॴ • CϥΠϒϥϦͷݺͼग़͠ • Swiftʹ͍ͭͯ΋ͬͱ஌Γ͍ͨͱ͖͸

  9. Swiftͷจ๏ͷ֓ཁ

  10. ཁ໿͢Δͱ͜Μͳ͔Μ͡ʂ • ϓϩτίϧࢦ޲ / ΦϒδΣΫτࢦ޲ /
 ؔ਺ܕ / ໋ྩܕ /

    ϒϩοΫߏ଄ • ڧ͍੩తܕ෇͚ / ܕਪ࿦ • Objective-C౳͔ΒͷӨڹ͋Γ • Swift4Ӷҙ੡࡞த • ܕ҆શnull҆શɻૉ੖Β͍͠ɻ • LLVMͱ͔ͳΜͱ͔ https://en.wikipedia.org/wiki/Swift_(programming_language)
  11. ϓϩτίϧࢦ޲ʁ

  12. Swiftyʹॻ্͘Ͱ೺Ѳ͓͖͍ͯͨ͜͠ͱ • Swiftʹ͸classͷଞʹstructɺenumɺprotocolΛ࣋ͭ • protocol͸”ಛఆͷॲཧͷͨΊͷϝιουͷઃܭਤ” • JavaͰ͍͏ͱ͜Ζͷinterface • ͭ·Γ࢖Θͳͯ͘΋ಈ͔ͳ͍͜ͱ͸ͳ͍ •

    Swift3ඪ४ϥΠϒϥϦͷ201γϯϘϧͷ͏ͪɺ
 struct͸140ݸɺenum͸12ݸɺprotocol͸48ݸɺ
 class͸ͳΜͱ1ݸʂ
  13. Java Comparable<T>ͱSwift Comparable • Java Comparable<T> • Swift Comparable μΠϚ

    http://qiita.com/S_Shimotori/items/83e22d83f5c0096a6d5b http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/lang/Comparable.java https://github.com/apple/swift/blob/c15c671372620b543e19a662218a247f601628e4/stdlib/public/core/Comparable.swift ※ ࣮ࡍ͸Equatableͷ “=” ͱComparableͷ ”<“ Λ࣮૷͢Ε͹଍ΓΔ
  14. OptionalͱCommandLine • Optional͸enum Optional<Wrapped> • .some(Wrapped)ͱ.noneΛྻڍ • Nullableͷਖ਼ମ • enum

    CommandLine͸ྻڍͯ͠ͳ͍ • ྻڍܕࣗ਎͕ΠχγϟϥΠζ͞Εͳ͍ಛੑΛར༻ https://github.com/apple/swift/blob/master/stdlib/public/core/CommandLine.swift https://github.com/apple/swift/blob/master/stdlib/public/core/Optional.swift Optional<String>ͷ౶ҥߏจ
  15. ͪͳΈʹ: ԋࢉࢠΛఆٛ͢Δ • Swift͸ࣗ෼ͰԋࢉࢠΛఆٛ͢Δ͜ͱ͕Մೳ • ओʹؔ਺ܕ͍ͨ͠ਓ͕࡞Δ “>=“ • ࢖͑Δه߸͸ແ೉ͦ͏ͳ΍ͭ •

    / = - + ! * % < > & | ^ ~ ?ͱ͔ଞ͍Ζ͍Ζ • ͑ʁ$͕ͩΊͳͷʹὺ͕࢖͑Δͷʁʁ
  16. ܕਪ࿦΋͋ΔΜͩͶ͐ ͍͍ͪͪܕΛॻ͔ͳ͍͍ͯ͘Ͷʂ

  17. SwiftͰܕਪ࿦ͱ͍ͬͨΒ…… • ʮίϯύΠϧ࣌ؒͷେ൒͕ܕਪ࿦͡ΌΜwʯ • ʮਪ࿦ʹ͔͔͔࣌ؒͬͨΒίϯύΠϧఘΊ·ͨ͠Τϥʔʯ • ղܾࡦ: • ৽͍͠όʔδϣϯͷSwift(ͱXcode9)Λ࢖͏ •

    એݴ࣌ʹͪΌΜͱܕΛॻ͘ • ؔ਺ܕͳΜͯͳ͔ͬͨɻ͍͍Ͷʁ
  18. ΤϥʔදݱͲ͏ͳͬͯΜͷʁ

  19. Swiftʹ͓͚ΔΤϥʔදݱ • جຊతʹ͸NonNullɺthrow΋ͳ͠ • ੒ޭ/ࣦഊͷ2஋͸໭Γ஋NullableͰදݱ • Optional.some(Wrapped)ͰแΜͰฦ͢ • Լॲཧ͠ͳ͍ͱแΜͩத਎͸࢖͑ͳ͍ʂ •

    ΑΓৄࡉͳΤϥʔදݱΛ͢ΔͳΒErrorΛ౤͛Δ • Τϥʔ͕ى͖ͳ͍͜ͱ͕໌Β͔ͳΒ͹”!”Ͱ௵͢
  20. ͓඼ॻ͖ • Swiftͷจ๏ͷ֓ཁ • Swift͕࢖͑Δ৔ॴ • CϥΠϒϥϦͷݺͼग़͠ • Swiftʹ͍ͭͯ΋ͬͱ஌Γ͍ͨͱ͖͸

  21. Swift͕࢖͑Δ৔ॴ

  22. ͋ʔ͸͍͸͍iOSͶ ڵຯͳ͍ΜͰ✋

  23. DarwinҎ֎Ͱ΋࢖͑Δ͔Βʂ ͕͢͞ʹ2.2͸ݹ͍͕

  24. LinuxͰSwift • swift.orgͷUbuntu༻όΠφϦ͔dockerΛ࢖͏ͷָ͕ • Կ͔࡞Δ࣌͸Swift Package ManagerΛ࢖͏ͱྑ͍ • ґଘؔ܎ղܾͨ͠Γςετͨ͠Γ͢Δ •

    ίϚϯυϥΠϯπʔϧ͕࡞ΕΔ • WebϑϨʔϜϫʔΫͰWebΞϓϦ͕࡞ΕΔ • Perfectͱ͔Vaporͱ͔ͦͷ΁Μ
  25. ͱ͜ΖͰ

  26. Swift͕Ͱ͖Δ͜ͱɺ୯඼Ͱ͸Ͱ͖ͳ͍͜ͱ • Swift಺ଂͷඪ४ϥΠϒϥϦ͕Ͱ͖Δ͜ͱ • هड़ʹඞཁͳػೳͷجຊ૚ • Stringͱ͔printͱ͔ͦ͏͍͏ͷ • “import Foundation”ͰͰ͖Δ͜ͱ

    • ΞϓϦͷجຊతͳػೳʹؔΘΔૢ࡞ • ϑΝΠϧͱ͔ηογϣϯͱ͔ͦ͏͍͏ͷ • Darwin༻FoundationͱLinux༻Foundation͸ผ෺ (௚༁)
  27. swift-corelibs-foundationਐḿঢ়گ(7݄17೔ݱࡏ) https://github.com/apple/swift-corelibs-foundation/blob/master/Docs/Status.md “Unimplemented”

  28. ͓඼ॻ͖ • Swiftͷจ๏ͷ֓ཁ • Swift͕࢖͑Δ৔ॴ • CϥΠϒϥϦͷݺͼग़͠ • Swiftʹ͍ͭͯ΋ͬͱ஌Γ͍ͨͱ͖͸

  29. CϥΠϒϥϦͷݺͼग़͠ (SPMͰͷ) iOS/macOS͸΋ͬͱ͔ΜͨΜɻ

  30. SPMͰCϥΠϒϥϦΛ࢖͏ • ޙൃݴޠΒ͘͠ͲΜͲΜઌഐͷҨ࢈Λ࢖͍ͬͯ͘ • Foundation͕ΞϨͳͷͰ࢖͍ݹ͞ΕͨϥΠϒϥϦͷ ํ͕҆৺ • SPMͰϥοϓ͠ɺ1ͭͷύοέʔδͱͯ͠ѻ͏ • ґଘϦετʹ͸Swiftͷ΋ͷ΋Cͷ΋ͷ΋ҰॹʹฒͿ

    • ໊લΛCHogeͱ͢Δ׳ྫ͕͋Δ • cURLͳΒCCurlͱ͔
  31. ໰୊͕ൃੜ͢Δ΍Γํ ΅͘ͷߟ͍͖͑ͨ͞ΐ͏ͷ41.ύοέʔδ ύοέʔδ" ύοέʔδ# ύοέʔδ$ *#.4XJGU $$VSM 44IJNPUPSJ $$VSM D63-

    ·Ί͖ͪ͠: IBM͸͕Μ͹ͬͯSwiftͯ͠Δɻ͍͍ͻͱɻ ໊લিಥ (ґଘݩˠґଘઌ)
  32. ͓඼ॻ͖ • Swiftͷจ๏ͷ֓ཁ • Swift͕࢖͑Δ৔ॴ • CϥΠϒϥϦͷݺͼग़͠ • Swiftʹ͍ͭͯ΋ͬͱ஌Γ͍ͨͱ͖͸

  33. Swiftʹ͍ͭͯ ΋ͬͱ஌Γ͍ͨͱ͖͸

  34. ͱΓ͋͑ͣॻ͖ͳ͕Β΍ͬͯΈ͍ͨʂ • ԦಓXcodeͰߦ͖͍ͨਓ • Xcode8ʹ͸ϦϑΝΫλϦϯάػೳ͕ͳ͍(স) • playgroundsͰؾܰʹॻ͚Δɺͨͷ͍͠ • JetBrainsڭͷਓ •

    iOSͱҰॹʹ΍ΔͳΒAppCodeɺpure SwiftͳΒCLion • Vimmer • ͪΌΜͱߋ৽͕௥͍͍ͭͯΔͷ͸ͳ͍Μ͡Ό… • Emacser • ͪΌΜͱߋ৽͞ΕͯΔɺͣΔ͍
  35. ͋ͱ͸͜ͷลಡΜͰ͓͘ͱ͍͍Αɻ • https://developer.apple.com/library/content/documentation/Swift/ Conceptual/Swift_Programming_Language/ • https://developer.apple.com/documentation/swift • https://swift.org/

  36. ·ͱΊ

  37. Swiftͷ͕͍͜͜͢͝ʂ • ڧ͍੩తܕ෇͚ͰprotocolͰenumͰ͍͢͝ʂ • αʔό΋ίϚϯυϥΠϯπʔϧ΋࡞ΕΔʂ • ͦΕPythonͰΑ͘ͳ͍ʁ • ಈతܕ෇͚͸அͯ͡Noɺઈରʹڐ͞ͳ͍ •

    ͦΕGo • ͦͷՄೳੑ͸͋Δ • ͦΕKotlin • ૉͰAWSLambda͍͚ΔΜͩ΋ΜͳʔͣΔ͍Αͳʔ