Accessing title of a MPMediaItem from an array, returns nil, although there exists one

125 Views Asked by At

Trying to save multiple playlists, and playback at a later time.

Here is the code, which configures the logic to display cell data.

let temp = rule?.valueForKey("music") as! NSArray
musicArray = temp as! [MPMediaItem]
print("musicArray = \(musicArray)=========>")
print(musicArray[0])
musicLabel.text = musicArray[0].title

Here is the error log,

musicArray = [<MPConcreteMediaItem: 0x147e98ce0> 4230548632108111364, <MPConcreteMediaItem: 0x147dbdb90> 1821425359156734603, <MPConcreteMediaItem: 0x147dc3630> 5879796615610011657, <MPConcreteMediaItem: 0x147dc61c0> 1821425359156734604]=========>RuleViewCell
<MPConcreteMediaItem: 0x147e98ce0> 4230548632108111364
fatal error: unexpectedly found nil while unwrapping an Optional value
0

There are 0 best solutions below