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
userfollowingarrayswift arrayvar userfollowingarray = [[string:any]]()get
dictionaryvariablevar 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
Post a Comment