-
Notifications
You must be signed in to change notification settings - Fork 873
/
Copy pathAppIntentDataModel.swift
34 lines (28 loc) · 1001 Bytes
/
AppIntentDataModel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import Foundation
@available(macOS 13, *)
public struct AppIntentDataModel: Codable, Equatable {
static let key: String = "appIntentData"
static let keyInternal: String = "appIntentData_Internal"
public init(alwaysUseDarkMode: Bool = false, useUnableStatus: Bool = false) {
self.alwaysUseDarkMode = alwaysUseDarkMode
self.useUnableStatus = useUnableStatus
}
public let alwaysUseDarkMode: Bool
public let useUnableStatus: Bool
func encoded() -> Data? {
let encoder = JSONEncoder()
do {
let appDataModelEncoded = try encoder.encode(self)
return appDataModelEncoded
} catch {
return nil
}
}
static func decoded(_ data: Data) -> AppIntentDataModel? {
let decoder = JSONDecoder()
guard let appDataModelDecoded = try? decoder.decode(AppIntentDataModel.self, from: data) else {
return nil
}
return appDataModelDecoded
}
}