Modify Object in Array with Swift?

前端 未结 2 1563
耶瑟儿~
耶瑟儿~ 2021-01-03 08:08

I have array:

var arrDicContact = udContact.valueForKey(\"arrDicContact\") as [NSDictionary]

and i want to change one contact in array:

2条回答
  •  庸人自扰
    2021-01-03 08:51

    You need to use an NSMutableDictionary instead, because you can't edit a NSDictionary.

    Then you've got also a typo. In your if-clause you use dic but you need dicx.

    After resolving that, in your if-clause you can do something like that:

    if (dicx.valueForKey("name") as String) == selectedName{
      dicx.setValue(value: yourObject, forKey: yourKey)
    }
    

提交回复
热议问题