ios - Can't add dictionaries with nil values to array in swift -


i trying create dictionary here:

var dicitem = ["dataofchange": 21-01-2012, "item": nil, "orderer": nil, "song": 1, "itemid": 3447, "petro": nil] 

i create dicitem in loop , in loop when create dicitem want add array: array.append(serstatdicitemusjson)
array:

var data = [[string:anyobject]]() 

but getting following error when try add array:

fatal error: attempt bridge implicitly unwrapped optional containing nil 

i think becouse of nil's can't figure how solve it.

the item in dictionary needs object. nil not object, , that's why got error.

there couple of solutions:

  1. use if statement check if value nil. add key/value pair dictionary when value not nil.

  2. use nsnull, object, instead of nil.

  3. write function converting nil empty string (""), , calling function every time want add dictionary.


Popular posts from this blog

javascript - Js, document.getElementById("ID").innerHTML, error -

objective c - Is there a way in OCMockito to make stubs fail when an unknown method is called? -

jquery - jqGrid update specific column data with out refreshing the entire column? -