// // LocalData.swift // Tusker // // Created by Shadowfacts on 8/18/18. // Copyright © 2018 Shadowfacts. All rights reserved. // import Foundation class LocalData { static let shared = LocalData() let defaults: UserDefaults private init() { if ProcessInfo.processInfo.environment.keys.contains("UI_TESTING") { defaults = UserDefaults(suiteName: "\(Bundle.main.bundleIdentifier!).uitesting")! if ProcessInfo.processInfo.environment.keys.contains("UI_TESTING_LOGIN") { defaults.set(true, forKey: onboardingCompleteKey) defaults.set(URL(string: "http://localhost:8080")!, forKey: instanceURLKey) defaults.set("client_id", forKey: clientIDKey) defaults.set("client_secret", forKey: clientSecretKey) defaults.set("access_token", forKey: accessTokenKey) } } else { defaults = UserDefaults() } } private let onboardingCompleteKey = "onboardingComplete" var onboardingComplete: Bool { get { return defaults.bool(forKey: onboardingCompleteKey) } set { defaults.set(newValue, forKey: onboardingCompleteKey) } } private let instanceURLKey = "instanceURL" var instanceURL: URL? { get { return defaults.url(forKey: instanceURLKey) } set { defaults.set(newValue, forKey: instanceURLKey) } } private let clientIDKey = "clientID" var clientID: String? { get { return defaults.string(forKey: clientIDKey) } set { defaults.set(newValue, forKey: clientIDKey) } } private let clientSecretKey = "clientSecret" var clientSecret: String? { get { return defaults.string(forKey: clientSecretKey) } set { defaults.set(newValue, forKey: clientSecretKey) } } private let accessTokenKey = "accessToken" var accessToken: String? { get { return defaults.string(forKey: accessTokenKey) } set { defaults.set(newValue, forKey: accessTokenKey) } } } extension Notification.Name { static let userLoggedOut = Notification.Name("userLoggedOut") }