我有一个名为arrayOfDict
的字典数组,其中包含许多具有相同键的字典对象:QUESTIONID
和OPTIONID
。
[ //arrayOfDict
{QUESTIONID:1, OPTIONID:0},
{QUESTIONID:2, OPTIONID:201},
{QUESTIONID:3, OPTIONID:204)
];
只有当我添加的词典不包含相同的arrayOfDict
时,我才需要将这些词典添加到QUESTIONID
。如果QUESTIONID
已经存在,那么相应的OPTIONID
需要替换为新的QUESTIONID
。如何将QUESTIONID
与arrayOfDict
中的beforeItemAdd
进行比较?
答案 0 :(得分:5)
你可以尝试获取相同问题的索引,如果你得到它,删除,否则只需插入它,试试这个:
# Without the "&" that cause the process to run in the background
cd ~/work; myapp &> /dev/null; cd -
# Without the " cd -" which returns my to the original directory
cd ~/work; myapp &> /dev/null &
答案 1 :(得分:0)
请检查:
var dict = arrayOfDict.map { dictionary -> ([String : Int]) in
var dicti = dictionary
if dicti["QUESTIONID"] == 1 { // You can change 1 with whatever `QUESTIONID` you want to check
dicti["OPTIONID"] = 1 // You can change 1 with whatever value you want to assign for `OPTIONID`
}
return dicti
}
print(dict)