Swift 4 Codable: Cannot exclude a property

Viewed 2573

I'm developing a simple music sequencer app. This kind of app tends to have a complex data structure which has to be saved/loaded, so the introduction of Codable protocol in Swift4 is totally a good news for me.

My problem is this: I have to have a non-Codable property. It doesn't have to be coded because it's a temporary variable only kept alive while the app is active. So I've just tried to exclude by implementing CodingKey, but the compiler still give me the error "Type 'Song' does not conform to protocol 'Decodable'".

Specifically I want to exclude "musicSequence" in the code below.

class Song : Codable { //Type 'Song' does not conform to protocol 'Decodable'
    var songName : String = "";    
    var tempo : Double = 120;

    // Musical structure
    var tracks : [Track] = [] // "Track" is my custom class, which conforms Codable as well    
    // Tones
    var tones = [Int : ToneSettings] (); // ToneSettings is also my custom Codable class

    var musicSequence : MusicSequence? = nil; // I get the error because of this line

    private enum CodingKeys: String, CodingKey {
        case songName
        case tempo
        case tracks
        case tones
    }

    func createMIDISequence () {
        // Create MIDI sequence based on "tracks" above
        // and keep it as instance variable "musicSequence"
    }
}

Does anybody have any ideas?

1 Answers
Related