From 6981ebeb23ec02fd5289a847542e68ba5ade4a2f Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 10 Jul 2024 09:57:04 +0200 Subject: [PATCH] More documentation --- LeStorage/StoreCenter.swift | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/LeStorage/StoreCenter.swift b/LeStorage/StoreCenter.swift index 0a8696c..3a84cf0 100644 --- a/LeStorage/StoreCenter.swift +++ b/LeStorage/StoreCenter.swift @@ -10,8 +10,10 @@ import UIKit public class StoreCenter { + /// The main instance public static let main: StoreCenter = StoreCenter() + /// A dictionary of Stores associated to their id fileprivate var _stores: [String : Store] = [:] /// The URL of the django API @@ -82,6 +84,7 @@ public class StoreCenter { // MARK: - Settings + /// Sets the user info given a user func setUserInfo(user: UserBase) { self._settingsStorage.update { settings in settings.userId = user.id @@ -89,13 +92,6 @@ public class StoreCenter { } } - /// Stores the user UUID - func setUserUUID(uuidString: String) { - self._settingsStorage.update { settings in - settings.userId = uuidString - } - } - /// Returns the stored user Id public var userId: String? { return self._settingsStorage.item.userId @@ -106,13 +102,6 @@ public class StoreCenter { return self._settingsStorage.item.username } - /// Sets the username - func setUserName(_ username: String) { - self._settingsStorage.update { settings in - settings.username = username - } - } - /// Returns the stored token public func token() -> String? { return try? self.service().keychainStore.getValue() @@ -140,6 +129,9 @@ public class StoreCenter { } } + /// Returns a generated device id + /// If created, stores it inside the keychain to get a consistent value even if the app is deleted + /// as UIDevice.current.identifierForVendor value changes when the app is deleted and installed again func deviceId() -> String { let keychainStore = KeychainStore(serverId: "lestorage.main") do { @@ -158,6 +150,7 @@ public class StoreCenter { // MARK: - Api Calls + /// Instantiates and loads an ApiCallCollection with the provided type func loadApiCallCollection(type: T.Type) { let apiCallCollection = ApiCallCollection() self._apiCallCollections[T.resourceName()] = apiCallCollection @@ -170,16 +163,6 @@ public class StoreCenter { } } - /// Returns or create the ApiCall collection matching the provided T type -// func getOrCreateApiCallCollection() -> ApiCallCollection { -// if let apiCallCollection = self._apiCallCollections[T.resourceName()] as? ApiCallCollection { -// return apiCallCollection -// } -// let apiCallCollection = ApiCallCollection() -// self._apiCallCollections[T.resourceName()] = apiCallCollection -// return apiCallCollection -// } - /// Returns the ApiCall collection using the resource name of the provided T type func apiCallCollection() throws -> ApiCallCollection { if let collection = self._apiCallCollections[T.resourceName()] as? ApiCallCollection { @@ -412,6 +395,7 @@ public class StoreCenter { // MARK: - Logs + /// Returns the logs collection and instantiates it if necessary fileprivate func _logsCollection() -> StoredCollection { if let logs = self._logs { return logs @@ -434,6 +418,7 @@ public class StoreCenter { // MARK: - Migration + /// Migrates the token from the provided service to the main Services instance public func migrateToken(_ services: Services) throws { guard let userName = self.userName() else { return