How to update key of dictionary in Swift 3 -


if (userfollowingarray[indexpath.row]["watcher_following"] as! bool) == false {     let dict : nsmutabledictionary = userfollowingarray[indexpath.row] as! nsmutabledictionary     print(dict)     dict["watcher_following"] = 1     self.userfollowingarray[indexpath.row] = dict as! dictionary<string, any> } 

i want update watcher_following key true/false throws exception.

[_ttgcs26_swiftdeferrednsdictionaryssp__ _swift_setobject:forkeyedsubscript:]: unrecognized selector sent instance

do not use nsmutable... collection types in swift

  • declare userfollowingarray swift array

    var userfollowingarray = [[string:any]]() 
  • get dictionary variable

    var dict = userfollowingarray[indexpath.row] 
  • check value

    if dict["watcher_following"] as! bool == false { 
  • update if necessary , assign dictionary array.

        dict["watcher_following"] = true     userfollowingarray[indexpath.row] = dict } 

    the last step necessary due value semantics

it's more convenient use custom struct or class rather dicionary.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -