How do you create an AVMutableMetadataItem for AVMetadataFormatiTunesMetadata

I am trying to update the track number of files using AVMutableMetadataItem's. I have been having some success except for AVMetadataFormatiTunesMetadata. I cannot seem to figure out what I need to set as the value to get this to work. I have tried to create an archive of a NSArray as follows

But I end up with a track and trackOf numbers that are way off. What exactly am I supposed to be passing in as the value for an AVMutableMetadataItem with a key of AVMetadataiTunesMetadataKeyTrackNumber?

It took me a very long time to figure that one out. Thanks to Apple's Core Audio documentation, which says absolutely nothing about how to deal with it. Or any of the other keys for that matter. I had to examine an MP4 file with track information before I understood.

Answer

You need to assign it with an NSData containing the track information.

The data must consists of four 16-bit big endian values, whereas the 2nd is the track number and the 3rd is the total tracks in collection. 1st and 4th should be zero.