Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save IgorMuzyka/0259fae2674ddae203ce552e5d8f32e3 to your computer and use it in GitHub Desktop.
Save IgorMuzyka/0259fae2674ddae203ce552e5d8f32e3 to your computer and use it in GitHub Desktop.
extension File where DataType: Restorable & Codable {
public func restore() throws -> DataType {
return try DataType.restore(from: path)
}
}
extension Readable where Self: Codable & Restorable {
public static func read(from path: Path) throws -> Self {
let data = try Data.read(from: path)
return try FileKit.jsonDecoder.decode(Self.self, from: data)
}
}
extension Writable where Self: Codable & Persistable {
public func write(to path: Path, atomically useAuxiliaryFile: Bool) throws {
let data = try FileKit.jsonEncoder.encode(self)
try data.write(to: path, atomically: useAuxiliaryFile)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment