AVMutableMetaDataItem cannot assign to value

Hello I am trying to assign some metadata to my AVExportSession so that the output files have the same metadata attached as the AVExportSession. I have tried import AVFoundation import AVKit and a combo of the two.

The AVMutableMetaDataItem.value is unable to be set because the compiler will reference NSObject.value property or its NSObject.setValue(forKey:) method

I have tried creating a playground and just creating the Mutable Metadata item without the same errors

When trying to subclass AVMutableMetaDataItem and trying to override its open var value property, the compiler will then complain the value we are overriding is read-only in reference to its non-mutable counterpart AVMetaDataItem.value

Does a radar need to be filled or is there something I am not doing correctly with creating an AVMutableMetaDataItem?

Answered by Engineer in 762597022

The value property of AVMutableMetadataItem has type (NSCopying & NSObjectProtocol)? and is settable. In order to assign to the value property you need an object that conforms to these protocols. Below is a code snippet that illustrates the basic idea:

let newLocationMetadataItem = AVMutableMetadataItem()
newLocationMetadataItem.identifier = AVMetadataIdentifier.quickTimeMetadataLocationISO6709
newLocationMetadataItem.dataType = kCMMetadataDataType_QuickTimeMetadataLocation_ISO6709 as String

let iso6709Geolocation = String(format: "%+08.4lf%+09.4lf/", -30.0368, -51.2090)
newLocationMetadataItem.value = iso6709Geolocation as NSString

I apologize, here is an edit for an earlier typo in my post I have tried creating a playground and just creating the Mutable Metadata item WITH the same errors

My work around for the time being has been using extraAttributes field instead, but after setting this metadataItem with the extraAttributes field populated to AVAssetExportSession.metadata = metaDataItem and regenerating a AVMutableMovie(url: assetExportSeshLocation) the resulting AVMutableMovie has an empty metadata field

Accepted Answer

The value property of AVMutableMetadataItem has type (NSCopying & NSObjectProtocol)? and is settable. In order to assign to the value property you need an object that conforms to these protocols. Below is a code snippet that illustrates the basic idea:

let newLocationMetadataItem = AVMutableMetadataItem()
newLocationMetadataItem.identifier = AVMetadataIdentifier.quickTimeMetadataLocationISO6709
newLocationMetadataItem.dataType = kCMMetadataDataType_QuickTimeMetadataLocation_ISO6709 as String

let iso6709Geolocation = String(format: "%+08.4lf%+09.4lf/", -30.0368, -51.2090)
newLocationMetadataItem.value = iso6709Geolocation as NSString
AVMutableMetaDataItem cannot assign to value
 
 
Q