Skip to content

Commit

Permalink
feat: New appRestorationVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Jun 24, 2024
1 parent a643dbc commit 58800ff
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Sources/InfomaniakCore/Account/UserDefaults+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
35 changes: 35 additions & 0 deletions Tests/InfomaniakCoreTests/Account/UserDefaults.swift
Original file line number Diff line number Diff line change
@@ -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.
}
}

}

0 comments on commit 58800ff

Please sign in to comment.