swift - Why can't I update a Dictionary Key:Value pair that has nil as the value? -


in following code:

var dict1: [string:int?] = ["blue" : 1, "red" : nil] let a: int? = dict1.updatevalue(2, forkey: "red") 

i error:

"cannot convert value of type 'int??' specified type 'int?' 
  1. what int?? mean?
  2. what's proper way update dictionaries if target pair has nil value?

the first question mark because dictionary's values int?. second question mark because call updatevalue returns optional wrapping 1 of dictionary's values. int??


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -