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
400
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
910
Other Decks in Technology
See All in Technology
AI時代のエンジニアキャリアについて今一度考える
sakamoto_582
1
1.1k
Keeping applications secure by evolving OAuth 2.0 and OpenID Connect
ahus1
PRO
1
130
AWS Summit 2026で見えたSIerにとっての Amazon Quickの位置づけ
maf_0521
0
160
Baseline対応のDOMの型定義を作った
uhyo
2
650
AIDLC_ヤフーショッピングの取り組み
lycorptech_jp
PRO
0
510
AWS Summit の片隅で、体育座りしながらコミュニティがにぎわう理由を考えた
k_adachi_01
2
340
Kotlin 開発のツラミを爆破した話! / Explode the difficulty of Kotlin dev!
eller86
0
140
ゼロをイチにする仕事が終わったあと
smasato
0
270
Text-to-SQLをAgentCoreで実現し、生成されるSQLの精度を定量的に評価する
yakumo
2
480
打造你的 AI 工作流:Agent Skill + MCP 實戰工作坊
appleboy
0
490
Tech-Verse 2026_Keynote
lycorptech_jp
PRO
0
130
型は壁、Rustでもバグを直すな、表現できなくせよ
nwiizo
5
370
Featured
See All Featured
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
440
BBQ
matthewcrist
89
10k
Bash Introduction
62gerente
615
220k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
230
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
800
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
Automating Front-end Workflow
addyosmani
1370
210k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
880
Designing Powerful Visuals for Engaging Learning
tmiket
1
430
Facilitating Awesome Meetings
lara
57
7k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
180
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/