|
Bogdan Timofte
authored
2 months ago
|
1
|
//
|
|
|
2
|
// ICloudDefault.swift
|
|
|
3
|
// USB Meter
|
|
|
4
|
//
|
|
|
5
|
// Created by Bogdan Timofte on 12/04/2020.
|
|
|
6
|
// Copyright © 2020 Bogdan Timofte. All rights reserved.
|
|
|
7
|
//
|
|
|
8
|
|
|
|
9
|
import Foundation
|
|
|
10
|
// https://github.com/lobodpav/Xcode11.4Issues/blob/master/Sources/Xcode11.4Test/CloudListener.swift
|
|
|
11
|
// https://medium.com/@craiggrummitt/boss-level-property-wrappers-and-user-defaults-6a28c7527cf
|
|
|
12
|
@propertyWrapper struct ICloudDefault<T> {
|
|
|
13
|
let key: String
|
|
|
14
|
let defaultValue: T
|
|
|
15
|
|
|
|
16
|
var wrappedValue: T {
|
|
|
17
|
get {
|
|
|
18
|
return NSUbiquitousKeyValueStore.default.object(forKey: key) as? T ?? defaultValue
|
|
|
19
|
}
|
|
|
20
|
set {
|
|
|
21
|
NSUbiquitousKeyValueStore.default.set(newValue, forKey: key)
|
|
|
22
|
/* MARK: Sincronizarea forțată
|
|
|
23
|
Face ca sincronizarea intre dispozitive mai repidă dar există o limita de update-uri catre iloud
|
|
|
24
|
*/
|
|
|
25
|
NSUbiquitousKeyValueStore.default.synchronize()
|
|
|
26
|
track("Pushed into iCloud value: '\(newValue)' for key: '\(key)'")
|
|
|
27
|
}
|
|
|
28
|
}
|
|
|
29
|
}
|