Browse Source

Return nil if archiving fails.

master
Abhi 2 years ago
parent
commit
a4cd914b4d
  1. 4
      Clocker/Clocker/LocationController.swift
  2. 4
      Clocker/Overall App/DataStore.swift
  3. 4
      Clocker/Overall App/Foundation + Additions.swift
  4. 4
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  5. 9
      Clocker/Panel/Notes Popover/NotesPopover.swift
  6. 4
      Clocker/Panel/ParentPanelController.swift
  7. 4
      Clocker/Preferences/General/PreferencesDataSource.swift
  8. 4
      Clocker/Preferences/General/PreferencesViewController.swift

4
Clocker/Clocker/LocationController.swift

@ -80,7 +80,9 @@ class LocationController: NSObject {
var datas: [Data] = []
for updatedObject in timezoneObjects {
let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject)
guard let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject) else {
continue
}
datas.append(dataObject)
}

4
Clocker/Overall App/DataStore.swift

@ -128,7 +128,9 @@ class DataStore: NSObject {
}
func addTimezone(_ timezone: TimezoneData) {
let encodedTimezone = NSKeyedArchiver.clocker_archive(with: timezone)
guard let encodedTimezone = NSKeyedArchiver.clocker_archive(with: timezone) else {
return
}
var defaults: [Data] = timezones()
defaults.append(encodedTimezone)

4
Clocker/Overall App/Foundation + Additions.swift

@ -58,7 +58,7 @@ public extension Data {
}
extension NSKeyedArchiver {
static func clocker_archive(with object: Any) -> Data {
static func clocker_archive(with object: Any) -> Data? {
if #available(macOS 10.14, *) {
return try! NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: true)
@ -67,5 +67,7 @@ extension NSKeyedArchiver {
if #available(macOS 10.13, *) {
return NSKeyedArchiver.archivedData(withRootObject: object)
}
return nil
}
}

4
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -421,7 +421,9 @@ extension TimezoneDataOperations {
func saveObject(at index: Int = -1) {
var defaults = store.timezones()
let encodedObject = NSKeyedArchiver.clocker_archive(with:dataObject as Any)
guard let encodedObject = NSKeyedArchiver.clocker_archive(with:dataObject as Any) else {
return
}
index == -1 ? defaults.append(encodedObject) : defaults.insert(encodedObject, at: index)
store.setTimezones(defaults)
}

9
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -315,8 +315,9 @@ class NotesPopover: NSViewController {
}
private func insertTimezoneInDefaultPreferences() {
guard let model = dataObject, var timezones = timezoneObjects else { return }
let encodedObject = NSKeyedArchiver.clocker_archive(with:model)
guard let model = dataObject, var timezones = timezoneObjects,
let encodedObject = NSKeyedArchiver.clocker_archive(with:model) else { return }
timezones[currentRow] = encodedObject
DataStore.shared().setTimezones(timezones)
}
@ -341,7 +342,9 @@ class NotesPopover: NSViewController {
var datas: [Data] = []
for updatedObject in timezoneObjects {
let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject)
guard let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject) else {
continue
}
datas.append(dataObject)
}

4
Clocker/Panel/ParentPanelController.swift

@ -285,7 +285,9 @@ class ParentPanelController: NSWindowController {
var datas: [Data] = []
for updatedObject in timezoneObjects {
let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject)
guard let dataObject = NSKeyedArchiver.clocker_archive(with: updatedObject) else {
continue
}
datas.append(dataObject)
}

4
Clocker/Preferences/General/PreferencesDataSource.swift

@ -184,7 +184,9 @@ extension PreferencesDataSource: NSTableViewDataSource {
}
private func insert(timezone: TimezoneData, at index: Int) {
let encodedObject = NSKeyedArchiver.clocker_archive(with: timezone)
guard let encodedObject = NSKeyedArchiver.clocker_archive(with: timezone) else {
return
}
var newDefaults = selectedTimezones
newDefaults[index] = encodedObject
store.setTimezones(newDefaults)

4
Clocker/Preferences/General/PreferencesViewController.swift

@ -977,7 +977,9 @@ extension PreferencesViewController: SRRecorderControlDelegate {}
// Helpers
extension PreferencesViewController {
private func insert(timezone: TimezoneData, at index: Int) {
let encodedObject = NSKeyedArchiver.clocker_archive(with: timezone)
guard let encodedObject = NSKeyedArchiver.clocker_archive(with: timezone) else {
return
}
var newDefaults = selectedTimeZones
newDefaults[index] = encodedObject
DataStore.shared().setTimezones(newDefaults)

Loading…
Cancel
Save