From 358d81b5cf54ef34986defbc6d69194c9c0aeb1d Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 31 Dec 2022 16:46:00 -0500 Subject: [PATCH] Fix crash when accessing SegmentedPageViewController before it's loaded --- Tusker/Screens/Timeline/TimelinesPageViewController.swift | 2 +- Tusker/Screens/Utilities/SegmentedPageViewController.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelinesPageViewController.swift b/Tusker/Screens/Timeline/TimelinesPageViewController.swift index 129b5057..eacb7f7b 100644 --- a/Tusker/Screens/Timeline/TimelinesPageViewController.swift +++ b/Tusker/Screens/Timeline/TimelinesPageViewController.swift @@ -85,7 +85,7 @@ class TimelinesPageViewController: SegmentedPageViewController NSUserActivity? { - return (currentViewController as! TimelineViewController).stateRestorationActivity() + return (currentViewController as? TimelineViewController)?.stateRestorationActivity() } func restoreActivity(_ activity: NSUserActivity) { diff --git a/Tusker/Screens/Utilities/SegmentedPageViewController.swift b/Tusker/Screens/Utilities/SegmentedPageViewController.swift index dd44ff92..30c1f6d8 100644 --- a/Tusker/Screens/Utilities/SegmentedPageViewController.swift +++ b/Tusker/Screens/Utilities/SegmentedPageViewController.swift @@ -23,8 +23,8 @@ class SegmentedPageViewController: UIPage var currentIndex: Int! { pages.firstIndex(of: currentPage) } - var currentViewController: UIViewController { - viewControllers!.first! + var currentViewController: UIViewController! { + viewControllers?.first } let segmentedControl = ScrollingSegmentedControl()