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
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
【CEDEC2026】コードレビュー支援ツール開発から学ぶ:LLMを用いた業務システムの実践的な運用設計と誤出力対策
cygames
PRO
0
530
モダンフロントエンド 開発研修
recruitengineers
PRO
1
300
クラウドセキュリティ入門 ~安全なクラウド利用のための基礎知識~
lhazy
8
7.6k
モノリス Rails でも日中に rails db:migrate を走らせたい! / Daytime rails db:migrate on Monolithic Rails!
euglena1215
3
380
20260801_スクフェス大阪
kgnkhkr
1
1.1k
ボトムアップ文化が強い組織で セキュリティをどう根付かせていくかの現在進行形の話 / Making Security Stick in a Bottom-Up Organization
yamaguchitk333
0
120
SmartHR Engineering Team Deck
smarthr
0
190
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
53k
toio・myCobotでフィジカルAIっぽいことを行うための検討(とりあえず調査) / フィジカルAI LT(IoTLTによる開催)
you
PRO
0
280
第3回しろおびセキュリティスポンサーセッション
log0417
0
140
AIが自社のTableauを操作する世界へ:Tableau MCP超入門
tbtykk
0
110
【CEDEC2026】『ウマ娘 プリティーダービー』 英語版のキャラクターの方言や口調をローカライズするための創造的アプローチ
cygames
PRO
1
180
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.1k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
680
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
390
Un-Boring Meetings
codingconduct
0
370
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Writing Fast Ruby
sferik
630
63k
Crafting Experiences
bethany
1
240
4 Signs Your Business is Dying
shpigford
187
22k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
A Tale of Four Properties
chriscoyier
163
24k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
210
Test your architecture with Archunit
thirion
1
2.3k
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/