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
For Developing URL Routing of SwiftUI App
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
freddi(Yuki Aki)
April 27, 2020
Technology
2k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
For Developing URL Routing of SwiftUI App
potatotips #69
https://potatotips.connpass.com/event/171532/
freddi(Yuki Aki)
April 27, 2020
More Decks by freddi(Yuki Aki)
See All by freddi(Yuki Aki)
輝け俺のViewController 〜海外iOSカンファレンス登壇編〜
freddi
4
420
Deep Dive into "any" and "some"
freddi
3
1.7k
挑戦!ISUCON de Server-side Swift 〜タイムゾーンには気をつけろ〜
freddi
0
2.1k
意外と知られてないXcode13の新しい参照カウンタ最適化オプションの挙動
freddi
2
200
How to develop SIL Optimizer in Swift Language
freddi
0
410
SwiftコンパイラがSwiftで開発できるようになる話
freddi
3
710
知ろう! ShazamKit
freddi
1
250
Swift Optimizing at Compiler World
freddi
2
900
Recap Pointfree Vol. 1~3
freddi
1
920
Other Decks in Technology
See All in Technology
13年運用タイトルのサーバーサイドが辿り着いた現在地 ― モンスターストライクにおける技術・組織・AI活用から得た知見
mixi_engineers
PRO
1
430
名古屋の市バスGTFS-JPデータ×スガキヤ 最寄りバス停検索をAmazon ElastiCache Serverless for Valkeyで最適化する
usanchuu
1
190
AI エージェント時代のデジタルアイデンティティ
fujie
3
1.4k
クラウドセキュリティ入門 ~安全なクラウド利用のための基礎知識~
lhazy
8
7.3k
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
53k
脱Jenkins、インターン生が挑んだCIツールGitHubActions移行
mixi_engineers
PRO
1
320
NetBoxを利用した作業効率化の試み_NetDevNight4
tnoha
0
450
事業価値と Engineering 2026年度版
recruitengineers
PRO
12
2.6k
VPCセキュリティ対応の最新事情
nagisa53
2
360
Forza Horizon 6 のテレメトリ機能で 自動運転に使えそうな学習データを集める話
henjin0
0
110
Atlassian Cloudサポート業務でのAIエージェント活用事例
smt7174
0
340
【CEDEC2026】『GRANBLUE FANTASY: Relink - Endless Ragnarok』のバトル制作事例 ~最高のキャラゲーを目指して~
cygames
PRO
0
160
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Balancing Empowerment & Direction
lara
6
1.2k
YesSQL, Process and Tooling at Scale
rocio
174
15k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
650
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
480
Skip the Path - Find Your Career Trail
mkilby
1
180
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.5k
How to train your dragon (web standard)
notwaldorf
97
6.7k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
How to Talk to Developers About Accessibility
jct
2
470
Transcript
For Developing URL Routing of SwiftUI App freddi - LINE
Fukuoka at potatotips (27th April, 2020)
Goal of This Presentation - SwiftUI(SceneDelegate)Ͱ࡞ΔΞϓϦͷURL Routing - URL RoutingΛ࣮͢ΔͨΊͷϕʔεࣝΛΔ
- iOS12·Ͱͷ࣮ͷҧ͍ΛΔ
URL Routing - URLͳͲΛ։͍ͨΒಛఆͷը໘ʹભҠ͢Δ https://snews.app/alerm snews://alerm
URL Routing - ࣮͢Δͷʹඞཁͳ͜ͱ - SceneDelegateͰURLΛύʔε (طଘͷํ๏ͱҧͬͯ͘Δ) - ύʔε݁ՌΛͱʹݱࡏ։͍͍ͯΔը໘͔ΒRouting -
ݱࡏͷը໘ͷ্ʹը໘Λදࣔ͢Δํ๏
Parse URL in AppDelegate (Old way) - AppDelegateͷapplication(_:, open:, options:)
- Ҏલ·ͰURLͷใ͜ͷؔʹ͞ΕΔ // application(_:, open:, options:) -> Bool func application(_ app: UIApplication, open url: URL, ...) -> Bool { // Write down URL Parsing Procedure ... return true }
Parse URL in SceneDelegate // scene(_:, openURLContexts:) func scene(_ scene:
UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { // Write down URL Parsing Procedure ... } New - SceneDelegateͷscene(_:, openURLContexts:) - AppDelegate൛Deprecated ※ SceneDelegateͷ͋ΔΞϓϦͰݺΕͳ͘ͳΔ
URL Routing - ࣮͢Δͷʹඞཁͳ͜ͱ - SceneDelegateͰURLΛύʔε - ύʔε݁ՌΛͱʹݱࡏ։͍͍ͯΔը໘͔ΒRouting - ݱࡏͷը໘ͷ্ʹը໘Λදࣔ͢Δํ๏
Route to Goal Screen from Current Screen - UIApplication.keyWindow Deprecated
Route to Goal Screen from Current Screen - SceneDelegate.window ΛΘΓʹ͏ͱྑ͍
import UIKit import SwiftUI class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? … New
Route to Goal Screen from Current Screen - UIWindow ͔ΒSwiftUIͷViewࣗମΛભҠͤ͞Δ͖ʁ
- …Ͱͳ͘ɺैདྷͲ͓ΓͷViewControllerͷํ͕ࣜྑ͍?
Route to Goal Screen from Current Screen - UIWindow ͔ΒSwiftUIͷViewࣗମΛભҠͤ͞Δ͖ʁ
- …Ͱͳ͘ɺैདྷͲ͓ΓͷViewControllerͷํ͕ࣜྑ͍? SwiftUIͷ .sheet ࣮࣭ViewControllerͷpresent
Route to Goal Screen from Current Screen - UIWindow ͔ΒSwiftUIͷViewࣗମΛભҠͤ͞Δ͖ʁ
- …Ͱͳ͘ɺैདྷͲ͓ΓͷViewControllerͷํ͕ࣜྑ͍? UIWindow UIHostingController(VC) SwiftUIͷ .sheet ࣮࣭ViewControllerͷpresent SwiftUI
Route to Goal Screen from Current Screen - UIWindow ͔ΒSwiftUIͷViewࣗମΛભҠͤ͞Δ͖ʁ
- …Ͱͳ͘ɺैདྷͲ͓ΓͷViewControllerͷํ͕ࣜྑ͍? UIWindow SwiftUIͷ .sheet ࣮࣭ViewControllerͷpresent .sheet .present UIHostingController(VC) SwiftUI UIHostingController(VC) SwiftUI
Route to Goal Screen from Current Screen func scene(_ scene:
UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { let url = URLContexts.first?.url let distinationView = parseURLToDistination(url: url) var currentTopVC = window?.rootViewController while true { if let presentedVC = currentTopVC?.presentedViewController { currentTopVC = presentedVC } else { break } } currentTopVC?.present(UIHostingController(rootView: distinationView), … }
Route to Goal Screen from Current Screen func scene(_ scene:
UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { let url = URLContexts.first?.url let distinationView = parseURLToDistination(url: url) var currentTopVC = window?.rootViewController while true { if let presentedVC = currentTopVC?.presentedViewController { currentTopVC = presentedVC } else { break } } currentTopVC?.present(UIHostingController(rootView: distinationView), … } urlΛऔಘ url͔ΒతͷViewΛऔಘ ݱࡏҰ൪্ʹදࣔ͞Ε͍ͯΔVCΛ୳ࡧ UIHostingControllerͰతͷViewΛ ୳ࡧͨ͠VCͷ্ʹදࣔ
URL Routing - ࣮͢Δͷʹඞཁͳ͜ͱ - SceneDelegateͰURLΛύʔε - ύʔε݁ՌΛͱʹݱࡏ։͍͍ͯΔը໘͔ΒRouting - ݱࡏͷը໘ͷ্ʹը໘Λදࣔ͢Δํ๏
Other Tips - NavigationࢹʹೖΕΔͳΒCoordinatorύλʔϯ - sheetNavigationLinkͷtagͷϑϥάཧ͕ࡶ - NavigationͰ͖ͳViewΛpushͯ͠ભҠ͢Δͷʁ - pushViewController૬ͷͷΛऔΓѻ͑ͳ͍
- NavigationΛUINavigationControllerͱͯ͠ѻ͑ͣ - NavigatorInsertionView(߲࣍)Λར༻͢Δ
NavigatorInsertionView struct NavigatorInsertionView: View { static var contentView: AnyView? =
nil var body: some View { NavigatorInsertionView.contentView ?? { () -> AnyView in assertionFailure("Could not get AnyView") return AnyView(EmptyView()) }() } }
NavigatorInsertionView struct NavigatorInsertionView: View NavigationLink("", destination: NavigatiorInsertionView(), tag: Coordinator.MovingState.on, selection:
movingState) .frame(width: 0, height: 0, alignment: .bottom)
Conclusion of URL Routing of SwiftUI App - ͍͔ͭ͘ͷؔiOS13͚ʹҠߦ͢Δ͜ͱʹͳΔ -
CoodinatorͷΑ͏ͳΫϥεΛ࡞Δํ͕ΕΔ͜ͱଟ͍ - SceneDelegateͷ scene(_ scene:, openURLContexts:) - Navigation͕ͳ͍ͳΒطଘͷVCͷpresentͰ͓̺
એ
https://hakata-swift.connpass.com/event/168308/