0

Just updated to Xcode 12.0 from the last version of Xcode 11/iOS13 and am getting an error in AppDelegate: Thread 1: "Subclass MPMediaItem must implement -valueForProperty: defined in [MPMediaItem class]."

When the app starts, I MPMediaQuery the library for songs and store them to a @Published variable in an Observable Object like this:

@Published var songs = [MPMediaItem]()


init() {
  self.songs = MPMediaQuery.songs().items
}

Later when I want to access a property I do so like this:

Text(self.observableObject.songs[0].title)

I’ve tried changing these to use .value(forProperty: "MPMediaItemPropertyTitle") but it doesn’t feel to be use a string over a property (and Xcode then pops up errors like Failed to produce diagnostic for expression; please file a bug report apple.) AFAIK, I’m not subclassing MPMediaItem anywhere and I’ve tried Googling the error above with no luck.

Anyone know what’s going on?

Ronni
  • 55
  • 1
  • 7

1 Answers1

1

I'm not sure if this is useful to your situation, but I recently came across a simiar problem.

In my case I needed to change 2 things that triggered this crash:

  1. I was initialising an empty MPMediaItem() as placeholder when no current song was loaded. The crash happened when trying to access a property (e.g. title) on this empty instance. Upon removing the empty MPMediaItem() and implementing a different placeholder approach, the problem went away.

  2. To test music on the simlator I was using a DummyMediaQuery: MPMediaQuery which returned an array of DummyMediaItem: MPMediaItem. In the DummyMediaItem class I did:

final class DummyMediaItem: MPMediaItem {
    private let _artist: String
    override var artist: String { return _artist }

    private let _title: String
    override var title: String { return _title }

    // and so on...

    // fix: crash in iOS 14
    override func value(forProperty property: String) -> Any? {
        return nil
    }
}
larromba
  • 306
  • 2
  • 11