mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2024-11-01 08:53:58 +00:00
26 lines
688 B
Swift
26 lines
688 B
Swift
|
//
|
||
|
// LocalSettings.swift
|
||
|
// DHBW-Service
|
||
|
//
|
||
|
// Created by Patrick Müller on 21.12.20.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
import Combine
|
||
|
|
||
|
private var cancellables = [String:AnyCancellable]()
|
||
|
|
||
|
extension Published {
|
||
|
init(wrappedValue defaultValue: Value, key: String) {
|
||
|
let value = UserDefaults.standard.object(forKey: key) as? Value ?? defaultValue
|
||
|
self.init(initialValue: value)
|
||
|
cancellables[key] = projectedValue.sink { val in
|
||
|
UserDefaults.standard.set(val, forKey: key)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class LocalSettings: ObservableObject {
|
||
|
@Published(wrappedValue: true, key: "IsFirstOpening") var isFirstOpening: Bool // To determine if the user is logged in
|
||
|
}
|