Created
May 9, 2018 22:01
-
-
Save IgorMuzyka/0259fae2674ddae203ce552e5d8f32e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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