Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Swift Package centered project - Build and Prac...
Search
d_date
September 19, 2021
Programming
20
13k
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
Share
More Decks by d_date
See All by d_date
TCA Practice in 5 min
d_date
2
1.1k
waiwai-swiftpm-part2
d_date
3
460
わいわいSwift PM part 1
d_date
2
370
What's new in Firebase 2021
d_date
2
1.4k
CI/CDをミニマルに構築する
d_date
1
530
How to write Great Proposal
d_date
4
1.1k
Thinking about Architecture for SwiftUI
d_date
8
2.3k
Integrate your app to modern world in Niigata
d_date
0
620
Integrate your app to modern world
d_date
2
620
Other Decks in Programming
See All in Programming
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Jakarta EE meets AI
ivargrimstad
0
720
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
630
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
Remix on Hono on Cloudflare Workers
yusukebe
1
300
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1k
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Optimizing for Happiness
mojombo
376
70k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
RailsConf 2023
tenderlove
29
900
Art, The Web, and Tiny UX
lynnandtonic
297
20k
BBQ
matthewcrist
85
9.3k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Why Our Code Smells
bkeepers
PRO
334
57k
GitHub's CSS Performance
jonrohan
1030
460k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Practical Orchestrator
shlominoach
186
10k
Transcript
Swift Packageத৺ͷ ϓϩδΣΫτߏͱͦͷ࣮ફ iOSDC JAPAN 2021 Daiki Matsudate @d_date
ٻΉ! Feedback #iosdc #c
🍣 #iosdc #c
લఏͷ֬ೝ Swift Package Manager Xcode Package.swift Multi Module Multi Project
SwiftUI UIKit Bundle Test Target
લఏͷ֬ೝ Swift Package Manager Xcode Package.swift Multi Module Multi Project
SwiftUI UIKit Bundle Test Target Fundamental Advanced
લఏͱͳΔࣝͷ֬ೝ
લఏͱͳΔࣝͷ֬ೝ • Buildʹ͍ͭͯ • Target • Con fi guration •
Scheme • Module / Framework • Import / Link • Static / Dynamic • XCFramework
Build Source Code Object Code Executable Binary Compiler Compile Link
Linker .o Build xcodebuild
Build Object Code DerivedData/*/Build/Intermediates.noindex/*.build/<env>/*.build/Object-normal/<Arch>/
Build Target • Buildʹ༻͍ΔϑΝΠϧʢInput) ੜʢOutput)Λఆٛͨ͠ͷ • Input: Source code, Framework,
Resource • Output: App, App Extension, Framework
Build Configuration • Build SettingsʢϏϧυʹؔ͢Δมͷू߹ʣͷϓϦηοτ
Build Scheme Target Configuration X
Build Scheme • Build5छྨ • Analyze • Test • Run
• Pro fi le • Archive Debug Release
Build Scheme Target Con fi guration Debug Release X Build
Analyze Run Test Pro fi le Archive
Module? Framework?
Module import͕Ͱ͖Δ୯Ґ
Module
Module • Derived Dataʹ.swiftmoduleͱ͍͏Bundle͕ଘࡏ͢Δ͜ͱ ※Bundle … σΟϨΫτϦ͚ͩͲϑΝΠϧͷΑ͏ʹৼΔ͏ܗࣜ • ιʔείʔυ͕ίϯύΠϧ·Ͱ͞ΕΔͱར༻ՄೳʹͳΔ
Module • Import͕Ͱ͖Δ୯Ґ (࣮ମ.swiftmodule) • moduleʹpublic APIؚ͕·ΕΔ • Module Stability
(swift 5.1~) • ҟͳΔSwiftͰੜ͞ΕͨϞδϡʔϧΛimportͰ͖Δʢ.swiftinterface)
Framework Build TargetͱϦϯΫ͢Δ ࣮ߦՄೳόΠφϦ
Framework • Build TargetͱLink͢Δ࣮ߦՄೳόΠφϦ • FrameworkBuild Targetʹ͢Δ͜ͱ͕Ͱ͖ΔʢModuleͰ͖ͳ͍ʣ →Build SchemeΛઃఆͰ͖Δ
FrameworkͷLink • ίϯύΠϧ͞ΕͨObject CodeΛΈ߹Θ͍ͤͯ͘࡞ۀ • Έ߹ΘͤΔࡍʹɺsymbolͷॏෳΛ֬ೝ͢Δ • Linkͷํʹ2छྨ • Static
Link -> Static Framework • Dynamic Link -> Dynamic Framework
Static Link Ϗϧυ࣌ʹObject codeΛͻͱͭʹ·ͱΊ͍ͯ͘ Link Link Link Link .o .o
.o
Load on Launch Dynamic Link ΞϓϦͷόΠφϦͱผʹੜ͠ɺΞϓϦ࣮ߦ࣌ʹಡΈࠐΉ Link Link Link .o
.o .o
Static Link vs Dynamic Link ΞϓϦͱͷLink ىಈ࣌ؒ Static Framework Ϗϧυͷͱ͖
͍ Dynamic Framework ΞϓϦىಈ࣌ ͍
Link in Module LinkModule୯ҐͰߦΘΕΔ Link .o .o .o .o .o
.o .o .o .o
XCFramework • ՄೳͳBundleܗࣜ • ෳͷFramework (ϏϧυࡁΈόΠφϦʣؚ͕·ΕΔ • Platform (iOS, macOS,
tvOS and watchOS) • Simulator / Device • Static / Dynamic • Build Architecture (x86_64, arm64, …)
͜ͷτʔΫͰ͞ͳ͍͜ͱ • Objective-CͷFramework • Module map • Bridging-Header • Library
(Frameworkͱݫີʹ۠ผ͠ͳ͍ʣ • .a • .dylib
https://www.youtube.com/watch?v=FZoYyAEPJ8w iOSDC Japan 2019: ϥΠϒϥϦͷΠϯϙʔτͱϦϯΫͷΈΛ୳Δ / Kishikawa Katsumi See also
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
͜Ε·Ͱ֬ೝͨ͜͠ͱ • Build • CompileͱLink • Build Target, Con fi
guration, Schemeͷؔ • Moduleͱimport • FrameworkͱLink • Static / Dynamic • XCFramework
Swift Package Manager
None
Swift Package Manager • Pros • swiftʹಉࠝ͞Ε͍ͯΔʢಛʹCIͰؔΘͬͯ͘Δʣ • Xcodeʹ౷߹͞Ε͍ͯΔ •
macOS / Linux྆ରԠ • ࣗಈͰґଘؔͷղܾɺߋ৽ • Cons • Compatible with Swift 5 and Xcode 11
Swift Package Manager in Xcode
None
None
None
8.1.1 Patch Minor Semantic Versioning Major Bug Fix Compatible Additions
Breaking Changes https://semver.org
8.1.1 9.0.0 < Up to Next Major 8.1.1 8.2.0 <
Up to Next Minor
None
None
None
None
None
None
Package.swiftͰ࢝ΊΔ ϓϩδΣΫτϑΝΠϧμΠΤοτ
None
None
None
None
None
None
Package.swift • Products • Library: Build TargetͱLink͢Δ࣮ߦՄೳόΠφϦ (=Framework) • Dependencies
• Targets • Target = Module • Sources/, Tests/ͷαϒσΟϨΫτϦ͕Ϟδϡʔϧ
None
AppFeature FeatureA Firebase FeatureB Link App Import Link Link Import
AppFeature
None
None
None
None
None
None
None
None
None
Package.swift • 3rd partyͷϥΠϒϥϦΛཧ͢Δ͚ͩͰͳ͍ • ModuleFrameworkΛࣗࡏʹߏͰ͖Δ → Multi Modules •
ϓϩδΣΫτϑΝΠϧ͕ܰྔʹ → Multi Projects
XCFramework in Package.swift
XCFramework in Package.swift • ιʔείʔυͰͳ͘όΠφϦܗࣜͰ͍ͯ͠Δ • e.g.) ࠂSDK, AnalyticsͳͲ •
targetʹ.binaryTargetΛ͏ • xcframeworkͦ͘͠ΕΛؚΉzipϑΝΠϧ • ϩʔΧϧͰϦϞʔτͰՄʢϦϞʔτchecksum͕ඞཁʣ
XCFramework in Package.swift
Swift PMʹରԠ͍ͯ͠ͳ͍߹
Swift PMʹରԠ͍ͯ͠ͳ͍߹ • Package.swift͕ͳ͍ → ιʔείʔυ͕ެ։͞Ε͍ͯΕϏϧυ͕ՄೳͳͷͰɺPull RequestΛग़͠ ͯPackage.swiftΛՃɻ͘͠Forkͯ͠Ճ • ιʔείʔυඇެ։ɺXCFrameworkͳ͍ʢFramework͔͠ͳ͍ʣ
→ CocoaPodsΛซ༻͢Δͷ͕खͬऔΓૣ͍ → Apple M1 (arm64) ͷ߹ Intel Mac (x86_64) ͰϏϧυ͞ΕͨFramework ѻ͑ͳ͍ͷͰ͢Δʢޙʹհʣ
Resources in Swift PM
Resources in Swift PM • Swift PMͰAssetsLocalizable.stringऔΓѻ͑Δ • Localize͢Δ߹Package.swiftʹdefaultLocalizationΛ͚ͭΔ
Resources in Swift PM • Bundle.moduleΛͬͯΞΫηε͢Δ
resource_bundle_accessor.swift
Localization in Swift PM Localization for Xcode Preview
Localization in Swift PM Localization for Xcode Preview
Localization in Swift PM Localization for Xcode Preview
Localization in Swift PM Localization for Build Target
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
Resources in Swift PM Best Practice https://developer.apple.com/videos/play/wwdc2020/10169
Resources in Swift PM BundleͲ͜ʁ
Swift PM with UIKit
Swift PM with UIKit • Xib, Storyboard͕Ϧιʔεѻ͍ʹͳΔ • Xib, StoryboardͰModuleΛࢦఆ͢Δ
• ࢦఆ͠ͳ͍ͱΫϥογϡ͢Δ • xibStoryboard͔ΒViewΛੜ͢ΔςετΛॻ͘ • IBLinterΛ͏
Swift PM with UIKit Use IBLinter https://github.com/IBDecodable/IBLinter
Multi module in Swift PM
Multi module in Swift PM Pros • ίϯύΠϧ࣌ؒͷॖ • Xcode
Previewͷ҆ఆԽ • App ClipͷΑ͏ͳ༰ྔ੍ݶ • Mini-Application
Mini-Application • ಛఆͷػೳModuleΛબͼɺFrameworkΛߏ • Build TargetʹFrameworkΛՃ͢Δ • ೝূը໘OnboardͳͲɺද͕ࣔ݅͋Δͷʹಛʹ༗ޮ
Multi module in Swift PM Best Practice • Common /
Misc moduleΛ࡞Βͳ͍ • ࡞Γͨ͘ͳͬͨΒͰ͖Δ͚ͩ࠷খ୯Ґʹׂ͢Δ • ResourceͷॏෳΛ͋·ΓڪΕͳ͍ • େ͖ͳը૾Λ৭ΜͳϞδϡʔϧͰ͍͍ͨ߹ͦΕࣗମΛϞδϡʔϧʹ͢ Δ
Multi projects in Swift PM
Multi projects in Swift PM • ϓϩδΣΫτͷׂ͕ബ͘ͳͬͨͷͰEnvironmentͷઃఆʹશৼΓͰ͖Δ • Staging.xcodeproj •
Production.xcodeproj • (Staging-M1.xcodeproj)
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͔ΒऔΓग़ͤΔΑ͏ʹ͢Δ
Multi projects in Swift PM Build Con fi guration vs
Multi Project • Xcode ProjectͰཧ͢ΔϑΝΠϧ͔͔ͨͩछྨ • ࢀর͢ΔϑΝΠϧಉ͡ͰҧͬͯΑ͍ • Project͕ҧ͏ͱϑΝΠϧ໊ॏෳͯ͠େৎ • e.g.) GoogleService-info.plist • Build Con fi gurationซ༻Ͱ͖Δ
Multi Projects Case Study • ARM64༻Xcode ProjectΛผͰ࡞Δ • CocoaPodsΛ͜ͷϓϩδΣΫτ͚ͩೖΕͳ͍Α͏ʹ͢Δ •
CocoaPodsʹೖ͍ͬͯΔϥΠϒϥϦimportͰ͖ͳ͘ͳΔͷͰ #if canImportͰճආ͢Δ
ࠓͷ·ͱΊ • ݴ༿ͷఆٛΛઆ໌Ͱ͖ΔΑ͏ʹ • PackageͰιʔείʔυΛཧ͠ɺϓϩδΣΫτϑΝΠϧΛܰ͘͢Δ • ϚϧνϞδϡʔϧͳߏͰϏϧυ࣌ؒͷॖMini Application • ෳͷϓϩδΣΫτϑΝΠϧͷӡ༻Ͱڥઃఆ͕؆୯ʹ
Case Study
GANMA! / FLINTERS, Inc. • UIKit based • CocoaPods /
Carthageͷซ༻ → CocoaPods / SwiftPMͷซ༻ • Ұ෦ͰXCFrameworkʹରԠ͍ͯ͠ͳ͍Pre built binary • Embedded FrameworkΛΊͨͷͰϓϩδΣΫτϑΝΠϧ͕খ͘͞ͳͬ ͨ • ΞϓϦαΠζ: 23.5MB → 20.6MB Case Study
Timee / Timee, inc. • UIKit based • CocoaPods /
Carthageͷซ༻ → CocoaPods / SwiftPMͷซ༻ • Ұ෦ͰXCFrameworkʹରԠ͍ͯ͠ͳ͍Pre built binary • ϓϩδΣΫτϑΝΠϧ͕খ͘͞ͳΓɺXcodeGenΛണ͕ͨ͠ • ηοτΞοϓ͕༰қʹ • ΞϓϦαΠζ: 30.3 MB → 26.9MB Case Study
NOT A HOTEL, Inc. • SwiftUI • Multi modules (16
→ 32 and more !) • Preview Apps • Multi projects • Staging • Production • (Staging-M1 Archived) Case Study
Case Study And you !!
Resources • https://github.com/pointfreeco/isowords • https://www.pointfree.co/episodes/ep142-a-tour-of-isowords-part-1 ʢpart 4·Ͱ͋Δʣ • https://date.notion.site/isowords-8f8982eb3a9a4665b2fa688b06791b70 •
https://date.notion.site/Swift-PM-Build- Con fi guration-4f14ceac795a4338a5a44748adfeaa40
ٻΉ! Feedback
Swift Packageத৺ͷ ϓϩδΣΫτߏͱͦͷ࣮ફ iOSDC JAPAN 2021 Daiki Matsudate @d_date