123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // O2UserDefaults.swift
- // O2OA_SDK_Framwork
- //
- // Created by FancyLou on 2018/11/7.
- //
- import Foundation
- import SwiftyUserDefaults
- // MARK: - 扩展自定义对象存储
- extension UserDefaults {
- subscript(key: DefaultsKey<O2BindUnitModel?>) -> O2BindUnitModel? {
- get { return unarchive(key) }
- set { archive(key, newValue) }
- }
-
- subscript(key: DefaultsKey<O2CenterServerModel?>) -> O2CenterServerModel? {
- get { return unarchive(key) }
- set { archive(key, newValue) }
- }
-
- subscript(key: DefaultsKey<O2LoginAccountModel?>) -> O2LoginAccountModel? {
- get { return unarchive(key) }
- set { archive(key, newValue) }
- }
-
- subscript(key: DefaultsKey<O2CustomStyleModel?>) -> O2CustomStyleModel? {
- get { return unarchive(key) }
- set { archive(key, newValue) }
- }
- subscript(key: DefaultsKey<O2BindDeviceModel?>) -> O2BindDeviceModel? {
- get { return unarchive(key) }
- set { archive(key, newValue) }
- }
- }
- // MARK:- 扩展定义的键
- extension DefaultsKeys {
- static let unit = DefaultsKey<O2BindUnitModel?>("O2unit")
- static let device = DefaultsKey<O2BindDeviceModel?>("O2device")
- static let deviceToken = DefaultsKey<String?>("deviceToken")
- static let centerServer = DefaultsKey<O2CenterServerModel?>("O2centerServer")
- static let myInfo = DefaultsKey<O2LoginAccountModel?>("O2myInfo")
- static let customStyle = DefaultsKey<O2CustomStyleModel?>("O2customStyle")
- static let customStyleHash = DefaultsKey<String?>("O2customStyleHash")
- }
- class O2UserDefaults {
-
- static let shared: O2UserDefaults = {
- return O2UserDefaults()
- }()
-
- private init() {}
-
- var myInfo: O2LoginAccountModel? {
- get {
- guard let me = Defaults[.myInfo] else {
- return nil
- }
- return me
- }
- set {
- Defaults[.myInfo] = newValue
- }
- }
- var unit: O2BindUnitModel? {
- get {
- guard let unit = Defaults[.unit] else {
- return nil
- }
- return unit
- }
- set {
- Defaults[.unit] = newValue
- }
- }
- var device: O2BindDeviceModel? {
- get {
- guard let device = Defaults[.device] else {
- return nil
- }
- return device
- }
- set {
- Defaults[.device] = newValue
- }
- }
- var deviceToken: String? {
- get {
- guard let token = Defaults[.deviceToken] else {
- return "deviceToken0x0x000000000xxxxxxxxxxxx"
- }
- return token
- }
- set {
- Defaults[.deviceToken] = newValue
- if let device = Defaults[.device] {
- device.name = newValue
- Defaults[.device] = device
- }
- }
- }
- var centerServer: O2CenterServerModel? {
- get {
- guard let server = Defaults[.centerServer] else {
- return nil
- }
- return server
- }
- set {
- Defaults[.centerServer] = newValue
- }
- }
- var customStyle: O2CustomStyleModel? {
- get {
- guard let style = Defaults[.customStyle] else {
- return nil
- }
- return style
- }
- set {
- Defaults[.customStyle] = newValue
- }
- }
- var customStyleHash: String? {
- get {
- guard let hash = Defaults[.customStyleHash] else {
- return ""
- }
- return hash
- }
- set {
- Defaults[.customStyleHash] = newValue
- }
- }
-
-
- }
|