Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Swift Package centered project - Build and Prac...

d_date
September 19, 2021

Swift Package centered project - Build and Practice

Swift Package中心のプロジェクト構成とその実践 - iOSDC JAPAN 2021
https://www.youtube.com/watch?v=e_T1-XrYf4A

d_date

September 19, 2021
Tweet

More Decks by d_date

Other Decks in Programming

Transcript

  1. લఏͷ֬ೝ Swift Package Manager Xcode Package.swift Multi Module Multi Project

    SwiftUI UIKit Bundle Test Target Fundamental Advanced
  2. લఏͱͳΔ஌ࣝͷ֬ೝ • Buildʹ͍ͭͯ • Target • Con fi guration •

    Scheme • Module / Framework • Import / Link • Static / Dynamic • XCFramework
  3. Build Scheme • Build͸5छྨ • Analyze • Test • Run

    • Pro fi le • Archive Debug Release
  4. Module • Import͕Ͱ͖Δ୯Ґ (࣮ମ͸.swiftmodule) • moduleʹ͸public APIؚ͕·ΕΔ • Module Stability

    (swift 5.1~) • ҟͳΔSwiftͰੜ੒͞ΕͨϞδϡʔϧΛimportͰ͖Δʢ.swiftinterface)
  5. XCFramework • ഑෍ՄೳͳBundleܗࣜ • ෳ਺ͷFramework (ϏϧυࡁΈόΠφϦʣؚ͕·ΕΔ • Platform (iOS, macOS,

    tvOS and watchOS) • Simulator / Device • Static / Dynamic • Build Architecture (x86_64, arm64, …)
  6. Homework https://twitter.com/kateinoigakukun/status/1405130382656163840?s=20 A, B, Cをアプリターゲット、静的ライブラリ、動的ライブラリのいずれかとする。A, B, Cの依存関係 が、 A ->

    B, A -> C, C -> Bとなるとき、Aのリンク時にSymbolが重複するかを考える。 A, B, Cが以下の場合、それぞれSymbolが重複するかを答えなさい。 ( 1 ) A: アプリターゲット, B: 静的ライブラリ, C: 動的ライブラリ ( 2 ) A: アプリターゲット, B: 静的ライブラリ, C: 静的ライブラリ ( 3 ) A: アプリターゲット, B: 動的ライブラリ, C: 静的ライブラリ https://twitter.com/kateinoigakukun/status/1405844501680197636?s=20 ग़యɿ ղ౴ɿ A B C
  7. ͜Ε·Ͱ֬ೝͨ͜͠ͱ • Build • CompileͱLink • Build Target, Con fi

    guration, Schemeͷؔ܎ • Moduleͱimport • FrameworkͱLink • Static / Dynamic • XCFramework
  8. Swift Package Manager • Pros • swiftʹಉࠝ͞Ε͍ͯΔʢಛʹCIͰؔΘͬͯ͘Δʣ • Xcodeʹ౷߹͞Ε͍ͯΔ •

    macOS / Linux྆ରԠ • ࣗಈͰґଘؔ܎ͷղܾɺߋ৽ • Cons • Compatible with Swift 5 and Xcode 11
  9. Package.swift • Products • Library: Build TargetͱLink͢Δ࣮ߦՄೳόΠφϦ (=Framework) • Dependencies

    • Targets • Target = Module • Sources/, Tests/ͷαϒσΟϨΫτϦ͕Ϟδϡʔϧ
  10. XCFramework in Package.swift • ιʔείʔυͰ͸ͳ͘όΠφϦܗࣜͰ഑෍͍ͯ͠Δ • e.g.) ޿ࠂSDK, AnalyticsͳͲ •

    targetʹ.binaryTargetΛ࢖͏ • xcframework΋͘͠͸ͦΕΛؚΉzipϑΝΠϧ • ϩʔΧϧͰ΋ϦϞʔτͰ΋ՄʢϦϞʔτ͸checksum͕ඞཁʣ
  11. Swift PMʹରԠ͍ͯ͠ͳ͍৔߹ • Package.swift͕ͳ͍
 → ιʔείʔυ͕ެ։͞Ε͍ͯΕ͹Ϗϧυ͕ՄೳͳͷͰɺPull RequestΛग़͠ ͯPackage.swiftΛ௥Ճɻ΋͘͠͸Forkͯ͠௥Ճ • ιʔείʔυඇެ։ɺXCFramework΋ͳ͍ʢFramework͔͠ͳ͍ʣ


    → CocoaPodsΛซ༻͢Δͷ͕खͬऔΓૣ͍
 → Apple M1 (arm64) ͷ৔߹͸ Intel Mac (x86_64) ͰϏϧυ͞ΕͨFramework ͸ѻ͑ͳ͍ͷͰ޻෉͢Δʢޙ൒ʹ঺հʣ
  12. Resources in Swift PM Best Practice ✅Ϧιʔε͸Ϟδϡʔϧຖʹ؅ཧ͢Δ • Resource Bundle

    Accessor (Bundle.module) ͸ಉ͡Ϟδϡʔϧ಺ͷϦιʔεʹର ͯ͠༗ޮ ⚠ ΋͠ଞͷϞδϡʔϧʹఏڙ͢Δඞཁ͕͋Δ৔߹͸ݸʑͷϦιʔεʹରͯ͠Typed Public AccessorΛఏڙ͢Δ • Ϧιʔεͷ໊લ͕֎෦ͱͷґଘؔ܎ͱͳͬͯ͠·͏ͨΊਪ঑͞Εͳ͍ 🚫 Resource Bundle΁ͷΞΫηεΛAPIʹ͠ͳ͍ https://developer.apple.com/videos/play/wwdc2020/10169
  13. Swift PM with UIKit • Xib, Storyboard͕Ϧιʔεѻ͍ʹͳΔ • Xib, Storyboard಺ͰModuleΛࢦఆ͢Δ

    • ࢦఆ͠ͳ͍ͱΫϥογϡ͢Δ • xib΍Storyboard͔ΒViewΛੜ੒͢ΔςετΛॻ͘ • IBLinterΛ࢖͏
  14. Multi module in Swift PM Pros • ίϯύΠϧ࣌ؒͷ୹ॖ • Xcode

    Previewͷ҆ఆԽ • App ClipͷΑ͏ͳ༰ྔ੍ݶ • Mini-Application
  15. Multi module in Swift PM Best Practice • Common /

    Misc moduleΛ࡞Βͳ͍ • ࡞Γͨ͘ͳͬͨΒͰ͖Δ͚ͩ࠷খ୯Ґʹ෼ׂ͢Δ • ResourceͷॏෳΛ͋·ΓڪΕͳ͍ • େ͖ͳը૾Λ৭ΜͳϞδϡʔϧͰ࢖͍͍ͨ৔߹͸ͦΕࣗମΛϞδϡʔϧʹ͢ Δ
  16. Multi projects in Swift PM Build Con fi guration vs

    Multi Project • Build Con fi gurationͰ؅ཧͰ͖Δͷ͸Build Settingsͷม਺
 Build SettingsͷUser-De fi nedʹΧελϜͳม਺ΛೖΕΔ • Info.plist͔ΒऔΓग़ͤΔΑ͏ʹ͢Δ
  17. Multi projects in Swift PM Build Con fi guration vs

    Multi Project • Xcode ProjectͰ؅ཧ͢ΔϑΝΠϧ͸͔͔ͨͩ਺छྨ • ࢀর͢ΔϑΝΠϧ͸ಉ͡Ͱ΋ҧͬͯ΋Α͍
 • Project͕ҧ͏ͱϑΝΠϧ໊͸ॏෳͯ͠΋େৎ෉ • e.g.) GoogleService-info.plist • Build Con fi guration΋ซ༻Ͱ͖Δ
  18. Multi Projects Case Study • ARM64༻Xcode ProjectΛผͰ࡞Δ • CocoaPodsΛ͜ͷϓϩδΣΫτ͚ͩೖΕͳ͍Α͏ʹ͢Δ •

    CocoaPodsʹೖ͍ͬͯΔϥΠϒϥϦ͸importͰ͖ͳ͘ͳΔͷͰ
 #if canImportͰճආ͢Δ
  19. GANMA! / FLINTERS, Inc. • UIKit based • CocoaPods /

    Carthageͷซ༻ → CocoaPods / SwiftPMͷซ༻ • Ұ෦ͰXCFrameworkʹରԠ͍ͯ͠ͳ͍Pre built binary • Embedded FrameworkΛ΍ΊͨͷͰϓϩδΣΫτϑΝΠϧ͕খ͘͞ͳͬ ͨ • ΞϓϦαΠζ: 23.5MB → 20.6MB Case Study
  20. Timee / Timee, inc. • UIKit based • CocoaPods /

    Carthageͷซ༻ → CocoaPods / SwiftPMͷซ༻ • Ұ෦ͰXCFrameworkʹରԠ͍ͯ͠ͳ͍Pre built binary • ϓϩδΣΫτϑΝΠϧ͕খ͘͞ͳΓɺXcodeGenΛണ͕ͨ͠ • ηοτΞοϓ͕༰қʹ • ΞϓϦαΠζ: 30.3 MB → 26.9MB Case Study
  21. NOT A HOTEL, Inc. • SwiftUI • Multi modules (16

    → 32 and more !) • Preview Apps • Multi projects • Staging • Production • (Staging-M1 Archived) Case Study