Swift dictionary bug?
dictionary, swift
Solution
Since the context does not provide enough information to infer the type, you'll need to explicitly name it as a dictionary, otherwise swift assumes it is an `NSDictionary` (I'm not clear on why though. I assume for better obj-c compatibility):
The following code all works:
// Playground
import UIKit
var str:NSString = "Hello, playground"
var d0 = [:]
var d1: Dictionary = [:]
d0.setValue(UIWebView(), forKey: "asdf")
d1["asdf"] = 1
d1["qwer"] = "qwer"
Problem
So I started a project in Swift, and I've come to this problem: this code works: ``` var dictionary = ["a":"valueOfA","b":"valueOfB","c":"valueOfC"] println(dictionary) dictionary["c"] = "newValOfC" println(dictionary) ``` and this doesn't: ``` var dictionary = [:] dictionary = ["a":"valueOfA","b":"valueOfB","c":"valueOfC"] println(dictionary) dictionary["c"] = "newValOfC" println(dictionary) ``` Gives an error: ``` Playground execution failed: error: <REPL>:35:17: error: cannot assign to the result of this expression dictionary["c"] = "newValC" ~~~~~~~~~~~~~~~ ^ ``` Notice that this is not a constant value So why doesn't the line ``` dictionary = ["a":"valueOfA","b":"valueOfB","c":"valueOfC"] ``` give an error?