nvzqz / FileKit

Simple and expressive file management in Swift
https://nvzqz.github.io/FileKit/docs/
MIT License
2.34k stars 208 forks source link

Codable doesn't conform to ReadableWritable #61

Closed tal closed 6 years ago

tal commented 6 years ago

I'm not sure if this is an oversight, but there's no default conformance for Codable to ReadableWriteable.

This conformance would allow for File<DataType: ReadableWritable> to work with any Codable and appears to be the intent as listed in the readme.

phimage commented 6 years ago

@tal If you have any idea of elegant implementation, you can propose it, or you can also PR

With the current implementation you can do that

// Just to be shorter if used many times, and this implement Codable using JSON encoder/decoder
typealias JSONReadableWritable = JSONWritable & JSONReadable 

struct Test: JSONReadableWritable {
    var test: String
}
// then you can use File<Test> or make an alias
typealias TestFile = File<Test> // File need a concrete type, no protocol

The encoder and decoder used are static variable in FileKit


I will add in FileKit JSONReadableWritable and PropertyListReadableWritable

doc edited for that https://github.com/nvzqz/FileKit/blob/develop/README.md#encodabledecodable