ios - Cannot assign value of type NSMutableArray to type UIBarButtonItem -


i developing ios audio app learning project. i'm having problem in 1 of functions, checks if player playing or paused/stopped. if it's playing should change button in button bar "pause" button, or if it's paused or stopped, change button "play" button. assigning button bar items variable "items" nsmutablearray, make necessary change button, assign "items" button bar items update display.

in code getting error on line:

self.toolbar.items = items 

the error message

cannot assign value of type nsmutablearray type uibarbuttonitem

i assume need cast nsmutablearray, i've tried using array, , when error goes away buttons break.

the related parts of code are:

@iboutlet weak var toolbar: uitoolbar!  @iboutlet var playbutton: uibarbuttonitem!   @ibaction func playpausepressed(sender: anyobject) {     let playbackstate = self.player.playbackstate mpmusicplaybackstate     let items = nsmutablearray(array: self.toolbar.items!)     if playbackstate == .stopped || playbackstate == .paused{         self.player.play()         items[2] = self.pausebutton     } else if playbackstate == .playing{         self.player.pause()         items[2] = self.playbutton     }     self.toolbar.items = items } 

any or direction appreciated. thanks!

the error occurs because nsmutablearray not related swift array

why not using native property directly? due reference semantics it's not necessary create temporary array.

@ibaction func playpausepressed(sender: anyobject) {     let playbackstate = self.player.playbackstate mpmusicplaybackstate     var items = self.toolbar.items!     if playbackstate == .stopped || playbackstate == .paused{         self.player.play()         items[2] = self.pausebutton     } else if playbackstate == .playing{         self.player.pause()         items[2] = self.playbutton     } } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -