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:
use
ifstatement check if valuenil. add key/value pair dictionary when value notnil.use
nsnull, object, instead ofnil.write function converting
nilempty string (""), , calling function every time want add dictionary.