-1

I've stored the MPMediaItem returned from MPMediaPickerController by saving its persistentID (which is a MPMediaEntityPersistentID). When I pass this to MPMediaQuery what I get back is a MPMediaEntity (superclass of MPMediaItem). Trying to cast this to a MPMediaItem is giving an exception.

    // recover MPMediaItem
    let predicateId = MPMediaPropertyPredicate(value: self.persistentID?.uint64Value,
                                               forProperty: MPMediaItemPropertyPersistentID,
                                               comparisonType:MPMediaPredicateComparison.equalTo)
    let query = MPMediaQuery.init()
    query.addFilterPredicate(predicateId)
    let collection = MPMediaItemCollection(items: query.items!)
    //at this point collection[0] contains a MPMediaEntry
Walt
  • 162
  • 1
  • 7

1 Answers1

-1

This was a misteak (sic.) that I'm curious why the compiler did not catch.

//at this point collection.items[0] contains the expected MPMediaItem
//why accessing collection[0] works at all is mysterious
Walt
  • 162
  • 1
  • 7
  • But none of your actual code ever _said_ `collection[0]`. That's just a phrase you use in some _comments_. — In any case, if that is now your question, make it part of your _question_. Do not ask a question in the answer field. – matt Jul 17 '18 at 19:11