You'd have to add the items iteratively and test for it manually. At a simple level something like this:
if string[newKey] == nil {
string[newKey] = newValue
} else {
//handle error
}
In reality it'd probably be more complex than that depending on the app logic behind it, but a better approach would be to design the app so that the situation can't occur in the first place.
I'd also suggest not using string
as a variable name, especially for something that is a Dictionary not a String!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…