Having difficulty trying to use an @Published property in my Mac app within a class that needs to be Codable.
This class is initialised using an AVMutableComposition
.
I followed this tutorial here and came up with the following, but not sure what to do to encode/decode an AVPlayerItem as the following code still gives me two errors:
Instance method 'decode(_:forKey:)' requires that 'AVPlayerItem' conform to 'Decodable'
and
Instance method 'encode(_:forKey:)' requires that 'AVPlayerItem' conform to 'Encodable'
class ProjectState2: ObservableObject, Codable {
enum CodingKeys: CodingKey{
case video
}
@Published var video: AVPlayerItem
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
video = try container.decode(AVPlayerItem.self, forKey: .video)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(video, forKey: .video)
}
}