Swifty Things

A number of not–so–obvious things in Swift.

var dict = [String: [Int]]()
dict["a", default: []].append(1)
var dict = [String: String?]() // Dict with value of type Optional should be avoided though
dict["a"] = nil // dict is empty, this removes the element from the dictionary
dict["a"] = nil as String? // dict.count == 1, value at key "a" is nil
comments powered by Disqus