From 27a609ac0358e22adb1055d90e56309dc10f17e7 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 6 Feb 2021 22:30:48 -0600 Subject: [PATCH] Update Foundation + Additions.swift --- .../Overall App/Foundation + Additions.swift | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Clocker/Overall App/Foundation + Additions.swift b/Clocker/Overall App/Foundation + Additions.swift index 28dae85..6b7336d 100644 --- a/Clocker/Overall App/Foundation + Additions.swift +++ b/Clocker/Overall App/Foundation + Additions.swift @@ -1,6 +1,7 @@ // Copyright © 2015 Abhishek Banthia import Cocoa +import CoreModelKit extension NSNotification.Name { static let themeDidChange = NSNotification.Name("ThemeDidChangeNotification") @@ -32,3 +33,26 @@ extension NSImage.Name { static let sortToggleAlternateIcon = NSImage.Name("Additional Preferences Highlighted Dynamic") static let menubarIcon = NSImage.Name("LightModeIcon") } + +extension Data { + // Extracting this out for tests + public func decode() -> SearchResult? { + let jsonDecoder = JSONDecoder() + do { + let decodedObject = try jsonDecoder.decode(SearchResult.self, from: self) + return decodedObject + } catch { + return nil + } + } + + public func decodeTimezone() -> Timezone? { + let jsonDecoder = JSONDecoder() + do { + let decodedObject = try jsonDecoder.decode(Timezone.self, from: self) + return decodedObject + } catch { + return nil + } + } +}