dn-m / MusicXML

Implementation of the musicXML specification in Swift
MIT License
74 stars 20 forks source link

Create a MusicXMLDecoder: XMLDecoder subclass #179

Open jsbean opened 5 years ago

jsbean commented 5 years ago

Now that we are disabling .trimValueWhitespaces from our decoder, it may make sense to create an XMLDecoder subclass MusicXMLDecoder.

This way we can use MusicXMLDecoder when testing atomic units, so we know we are working with the same thing when decoding a whole MusicXML object.

This will also allow us to wipe XMLCoder from testing, which has seemed slightly out of place.

jsbean commented 5 years ago

(This could also be made symmetrical as MusicXMLEncoder.)

jsbean commented 5 years ago

We could also tighten up the API a little, because we know we are always dealing with .utf8:

extension MusicXMLDecoder {
    func decode <T> (_ type: T.Type, from string: String) throws -> T where T: Decodable {
        return try decode(type, string.data(using: utf8)!)
    }
}