Array as a dictionary value in swift language -
i have following swift dictionary
var list = [ 2543 : [ "book", "pen" ], 2876 : [ "school", "house"] ]
how can access array values ?
println(list[2543][0])
the above code gives error "could not find member subscript"
and should print "book"
note subscript
returns optional. have force unwrapping:
println(list[2543]![0])
or use optional chaining
println(list[2543]?[0])
Comments
Post a Comment