mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Refactor SyncCore
This commit is contained in:
37
submodules/SyncCore/Sources/AppConfiguration.swift
Normal file
37
submodules/SyncCore/Sources/AppConfiguration.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
import Foundation
|
||||
#if os(macOS)
|
||||
import PostboxMac
|
||||
#else
|
||||
import Postbox
|
||||
#endif
|
||||
|
||||
public struct AppConfiguration: PreferencesEntry, Equatable {
|
||||
public var data: JSON?
|
||||
|
||||
public static var defaultValue: AppConfiguration {
|
||||
return AppConfiguration(data: nil)
|
||||
}
|
||||
|
||||
init(data: JSON?) {
|
||||
self.data = data
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.data = decoder.decodeObjectForKey("data", decoder: { JSON(decoder: $0) }) as? JSON
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
if let data = self.data {
|
||||
encoder.encodeObject(data, forKey: "data")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "data")
|
||||
}
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
guard let to = to as? AppConfiguration else {
|
||||
return false
|
||||
}
|
||||
return self == to
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user