MPMediaEntity.enumerateValues is broken and has been broken in Swift for a very long time. At last one Radar (rdar://40779720) was apparently filed in 2018.
The issue is that the block passed to enumerateValues can be called with a nil value when there are no properties of the requested type. To be clear, it is not that one or more of the arguments to the block may be nil, but rather that the block itself will be called with a nil value. This is an ObjC convention that does not translate to Swift and Apple has never bothered to fix this issue in MPMediaEntity.
The only/best workaround of which I'm aware can be found here: https://gist.github.com/StephenHeaps/40ea93012600f7e9abad9bd9bdc9084b
This fix is in the ObjC domain thus you will have to import these files and update/create a bridging header for use in Swift.
Full disclaimer. This is not my fix but I am greatly thankful to StephenHeaps on GitHub for the GIST.
Post
Replies
Boosts
Views
Activity
JoeKun, thanks for further researching and acknowledging the issue. That said, I agree with blue0615 that this decision should be reconsidered. I too have a great deal of time, effort, and product design centered around this capability which to this point has never been documented to be "off limits" to 3rd party apps. I have used this capability in my app since iOS 13. To arbitrarily change this functionality without warning or consideration of 3rd party developers is simply unfair, to put it mildly.
Thanks for asking/answering this question. I had a similar issue with code that has been in use since at least iOS 8.
Do you have further insight into what changes occurred in iOS16 that precipitated this change being necessary?