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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -