From ddd79dbe113306935a69835a6544d8ea0eb9193f Mon Sep 17 00:00:00 2001 From: Harry-KNIGHT Date: Wed, 29 Nov 2023 20:03:22 +0100 Subject: [PATCH] Simplify if let unwrapping for userdefaults --- ControlRoom/Controllers/ColorHistoryController.swift | 9 ++++----- ControlRoom/Controllers/DeepLinksController.swift | 9 ++++----- ControlRoom/Controllers/LocationsController.swift | 9 ++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/ControlRoom/Controllers/ColorHistoryController.swift b/ControlRoom/Controllers/ColorHistoryController.swift index 5c2941e..dd76d61 100644 --- a/ControlRoom/Controllers/ColorHistoryController.swift +++ b/ControlRoom/Controllers/ColorHistoryController.swift @@ -18,11 +18,10 @@ class ColorHistoryController: ObservableObject { /// Attempts to load saved colors from UserDefaults, or creates an empty array otherwise. init() { - if let data = UserDefaults.standard.data(forKey: defaultsKey) { - if let decoded = try? JSONDecoder().decode([PickedColor].self, from: data) { - colors = decoded - return - } + if let data = UserDefaults.standard.data(forKey: defaultsKey), + let decoded = try? JSONDecoder().decode([PickedColor].self, from: data) { + colors = decoded + return } colors = [] diff --git a/ControlRoom/Controllers/DeepLinksController.swift b/ControlRoom/Controllers/DeepLinksController.swift index 87cef67..75b3e01 100644 --- a/ControlRoom/Controllers/DeepLinksController.swift +++ b/ControlRoom/Controllers/DeepLinksController.swift @@ -18,11 +18,10 @@ class DeepLinksController: ObservableObject { /// Attempts to load saved links from UserDefaults, or creates an empty array otherwise. init() { - if let data = UserDefaults.standard.data(forKey: defaultsKey) { - if let decoded = try? JSONDecoder().decode([DeepLink].self, from: data) { - links = decoded - return - } + if let data = UserDefaults.standard.data(forKey: defaultsKey), + let decoded = try? JSONDecoder().decode([DeepLink].self, from: data) { + links = decoded + return } links = [] diff --git a/ControlRoom/Controllers/LocationsController.swift b/ControlRoom/Controllers/LocationsController.swift index 4d70470..31cccf7 100644 --- a/ControlRoom/Controllers/LocationsController.swift +++ b/ControlRoom/Controllers/LocationsController.swift @@ -18,11 +18,10 @@ class LocationsController: ObservableObject { /// Attempts to load saved locations from UserDefaults, or creates an empty array otherwise. init() { - if let data = UserDefaults.standard.data(forKey: defaultsKey) { - if let decoded = try? JSONDecoder().decode([Location].self, from: data) { - locations = decoded - return - } + if let data = UserDefaults.standard.data(forKey: defaultsKey), + let decoded = try? JSONDecoder().decode([Location].self, from: data) { + locations = decoded + return } locations = []