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
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
390
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
400
SwiftコンパイラがSwiftで開発できるようになる話
freddi
3
710
知ろう! ShazamKit
freddi
1
240
Swift Optimizing at Compiler World
freddi
2
900
Recap Pointfree Vol. 1~3
freddi
1
900
Other Decks in Technology
See All in Technology
MCP Appsを作ってみよう
iwamot
PRO
4
530
Oracle AI Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
6
1.5k
AGENTS.mdとSkillsで始めるAIエージェント活用
sonoda_mj
2
190
ポケモンの型をTypeScriptの型システムで表現してみた
subroh0508
0
370
脆弱性対応、どこで線を引くか
rymiyamoto
0
360
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.9k
LLMにもCAP定理があるという話
harukasakihara
0
290
就職⽀援サービスにおけるキャリアアドバイザーのシフトスケジューリング
recruitengineers
PRO
1
140
2026TECHFRESH畢業分享會 - 葬送的通靈師:化系統與用戶雜訊成行動訊號
line_developers_tw
PRO
0
770
作って終わりにしない タイミーのセマンティックレイヤー育成の現在地
chanyou0311
3
2.2k
2026 TECHFRESH 畢業分享會 - AI-Native 重塑軟體工程與虛擬講師
line_developers_tw
PRO
0
770
SIer20年! 培ったスキルがスタートアップで輝く時
shucho0103
0
830
Featured
See All Featured
Balancing Empowerment & Direction
lara
6
1.2k
How to Ace a Technical Interview
jacobian
281
24k
Prompt Engineering for Job Search
mfonobong
0
340
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
180
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
160
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
410
Everyday Curiosity
cassininazir
0
230
We Have a Design System, Now What?
morganepeng
55
8.2k
Unsuck your backbone
ammeep
672
58k
Automating Front-end Workflow
addyosmani
1370
210k
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/