2021-04-26 10:57:50 +02:00
|
|
|
//
|
|
|
|
// UserDefaults.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-4-26.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
extension UserDefaults {
|
|
|
|
|
2021-07-19 11:12:45 +02:00
|
|
|
public subscript<T: RawRepresentable>(key: String) -> T? {
|
2021-04-26 10:57:50 +02:00
|
|
|
get {
|
|
|
|
if let rawValue = value(forKey: key) as? T.RawValue {
|
|
|
|
return T(rawValue: rawValue)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
set { set(newValue?.rawValue, forKey: key) }
|
|
|
|
}
|
|
|
|
|
2021-07-19 11:12:45 +02:00
|
|
|
public subscript<T>(key: String) -> T? {
|
2021-04-26 10:57:50 +02:00
|
|
|
get { return value(forKey: key) as? T }
|
|
|
|
set { set(newValue, forKey: key) }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|