From ad0a9ecafe1062af83190c5002475e8e24acd75b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 28 Feb 2023 22:42:28 -0500 Subject: [PATCH] Fix crash when setting SegmentedPageViewController pages to [] after failing to decode pinned timelines --- Tusker/CoreData/AccountPreferences.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tusker/CoreData/AccountPreferences.swift b/Tusker/CoreData/AccountPreferences.swift index bdc84472..53f990d1 100644 --- a/Tusker/CoreData/AccountPreferences.swift +++ b/Tusker/CoreData/AccountPreferences.swift @@ -24,15 +24,17 @@ public final class AccountPreferences: NSManagedObject { @NSManaged var createdAt: Date @NSManaged var pinnedTimelinesData: Data? - @LazilyDecoding(from: \AccountPreferences.pinnedTimelinesData, fallback: []) + @LazilyDecoding(from: \AccountPreferences.pinnedTimelinesData, fallback: AccountPreferences.defaultPinnedTimelines) var pinnedTimelines: [PinnedTimeline] static func `default`(account: LocalData.UserAccountInfo, context: NSManagedObjectContext) -> AccountPreferences { let prefs = AccountPreferences(context: context) prefs.accountID = account.id prefs.createdAt = Date() - prefs.pinnedTimelines = [.home, .public(local: true), .public(local: false)] + prefs.pinnedTimelines = Self.defaultPinnedTimelines return prefs } + private static let defaultPinnedTimelines = [PinnedTimeline.home, .public(local: true), .public(local: false)] + }