From 58800ff714d47eb40205011be6c1d428022023fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Mon, 24 Jun 2024 08:30:58 +0200 Subject: [PATCH] feat: New appRestorationVersion --- .../Account/UserDefaults+Extension.swift | 22 +++++++++--- .../Account/UserDefaults.swift | 35 +++++++++++++++++++ 2 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 Tests/InfomaniakCoreTests/Account/UserDefaults.swift diff --git a/Sources/InfomaniakCore/Account/UserDefaults+Extension.swift b/Sources/InfomaniakCore/Account/UserDefaults+Extension.swift index b0db01f..decc14c 100644 --- a/Sources/InfomaniakCore/Account/UserDefaults+Extension.swift +++ b/Sources/InfomaniakCore/Account/UserDefaults+Extension.swift @@ -26,15 +26,19 @@ public extension UserDefaults { self.rawValue = rawValue } - // TODO: Clean hotfix static let legacyIsFirstLaunch = Keys(rawValue: "isFirstLaunch") static let currentUserId = Keys(rawValue: "currentUserId") + static let appRestorationVersion = Keys(rawValue: "appRestorationVersion") } func key(_ key: Keys) -> String { return key.rawValue } +} + +// MARK: - Public extension +public extension UserDefaults { var currentUserId: Int { get { return integer(forKey: key(.currentUserId)) @@ -44,19 +48,27 @@ public extension UserDefaults { } } - // TODO: Clean hotfix var legacyIsFirstLaunch: Bool { get { - if object(forKey: key(.legacyIsFirstLaunch)) != nil { - return bool(forKey: key(.legacyIsFirstLaunch)) - } else { + guard let isFirstLaunch = object(forKey: key(.legacyIsFirstLaunch)) as? Bool else { return true } + + return isFirstLaunch } set { set(newValue, forKey: key(.legacyIsFirstLaunch)) } } + + var appRestorationVersion: Int? { + get { + return object(forKey: key(.appRestorationVersion)) as? Int + } + set { + set(newValue, forKey: key(.appRestorationVersion)) + } + } } // MARK: - Internal extension diff --git a/Tests/InfomaniakCoreTests/Account/UserDefaults.swift b/Tests/InfomaniakCoreTests/Account/UserDefaults.swift new file mode 100644 index 0000000..13b7a45 --- /dev/null +++ b/Tests/InfomaniakCoreTests/Account/UserDefaults.swift @@ -0,0 +1,35 @@ +// +// UserDefaults.swift +// +// +// Created by adrien on 24.06.2024. +// + +import XCTest + +final class UserDefaults: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + // Any test you write for XCTest can be annotated as throws and async. + // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. + // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +}