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
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Quine, Polyglot, 良いコード
qnighy
4
640
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
190
Outline View in SwiftUI
1024jp
1
330
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
880
CSC509 Lecture 13
javiergs
PRO
0
110
Featured
See All Featured
Six Lessons from altMBA
skipperchong
27
3.5k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
We Have a Design System, Now What?
morganepeng
50
7.2k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Visualization
eitanlees
145
15k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
For a Future-Friendly Web
brad_frost
175
9.4k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Embracing the Ebb and Flow
colly
84
4.5k
Building Applications with DynamoDB
mza
90
6.1k
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