Fix crash when setting SegmentedPageViewController pages to [] after failing to decode pinned timelines

This commit is contained in:
Shadowfacts 2023-02-28 22:42:28 -05:00
parent ee630cf9df
commit ad0a9ecafe
1 changed files with 4 additions and 2 deletions

View File

@ -24,15 +24,17 @@ public final class AccountPreferences: NSManagedObject {
@NSManaged var createdAt: Date @NSManaged var createdAt: Date
@NSManaged var pinnedTimelinesData: Data? @NSManaged var pinnedTimelinesData: Data?
@LazilyDecoding(from: \AccountPreferences.pinnedTimelinesData, fallback: []) @LazilyDecoding(from: \AccountPreferences.pinnedTimelinesData, fallback: AccountPreferences.defaultPinnedTimelines)
var pinnedTimelines: [PinnedTimeline] var pinnedTimelines: [PinnedTimeline]
static func `default`(account: LocalData.UserAccountInfo, context: NSManagedObjectContext) -> AccountPreferences { static func `default`(account: LocalData.UserAccountInfo, context: NSManagedObjectContext) -> AccountPreferences {
let prefs = AccountPreferences(context: context) let prefs = AccountPreferences(context: context)
prefs.accountID = account.id prefs.accountID = account.id
prefs.createdAt = Date() prefs.createdAt = Date()
prefs.pinnedTimelines = [.home, .public(local: true), .public(local: false)] prefs.pinnedTimelines = Self.defaultPinnedTimelines
return prefs return prefs
} }
private static let defaultPinnedTimelines = [PinnedTimeline.home, .public(local: true), .public(local: false)]
} }