Reputation: 2837
How is it that this code is crashing when calling tableView.reloadData()
??
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let count = self.player.queueForPlayer.count
return count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let song: MPMediaItem = self.player.queueForPlayer.items[indexPath.row] // EXC_BAD_ACCESS !!!
/// etc.
}
So the queueForPlayer.items array is not mutated in this time. queueForPlayer is of type MPMediaItemCollection
The items array has 100 elements in it, and my table code crashes on IndexPath section 0, row 1.
I mean this seems to be pretty basic stuff, so all I can think of is that the MPMediaItem data type is doing something funky?
When I debug with Address Sanitizer, and try listing the .queue, it puts this in the console:
-[MPConcreteMediaItem retain]: message sent to deallocated instance 0x161ccc0d0
Because there is no public API for MPConcreteMediaItem
, so I'm thinking this is why Apple doesn't expose the MPMusicPlayerController
queue? I don't think we're supposed to retain MPMediaItem
objects? I don't know.
UPDATE: When I stepped through slowly, and inspected other aspects of the code, it would then not crash. So I suspect I have some sort of race condition? Or Apple has one of its "pseudo-synchronous" API methods that in fact isn't?
Should i instead just store an array to persistentID values, then each time I need info about the MPMediaItem I can do (individual, ugh) media queries on them?
Upvotes: 1
Views: 105