Skip to content

Instantly share code, notes, and snippets.

@joshbernfeld
joshbernfeld / CMTime+Codable.swift
Created January 11, 2018 05:07
Swift encoding/decoding support for CMTime
extension CMTime: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.value = try container.decode(CMTimeValue.self, forKey: .value)
self.timescale = try container.decode(CMTimeScale.self, forKey: .timescale)
self.flags = CMTimeFlags(rawValue: try container.decode(UInt32.self, forKey: .flags))
self.epoch = try container.decode(CMTimeEpoch.self, forKey: .epoch)
}