MusicXML
MusicXML copied to clipboard
Create a MusicXMLDecoder: XMLDecoder subclass
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.
(This could also be made symmetrical as MusicXMLEncoder
.)
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)!)
}
}