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

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -