Reputation: 171
var dict = ["name": "ryan", "age": 13, "gender": "male"]
//error on the next line
dict["hairColor"] = "brown"
In the tutorial I'm watching the snippet above is working, but not for me. The error says:
cannot assisgn to the result of this expression.
Upvotes: 0
Views: 201
Reputation: 38238
I can reproduce your problem in older versions of Xcode, such as 6.0.1. It works fine in the latest version, 6.1.1. You should update your Xcode.
You'll also need to import Foundation
(or import it implicitly through import UIKit
or import Cocoa
, either of which will also include Foundation) for the code to work, as that allows the compiler to assume you want a dictionary of NSObject
s, because you're trying to put mixed types (integer and string) into the Dictionary. This complete example works fine in 6.1.1:
import Foundation // Or Cocoa, or UIKit
var dict = ["name": "ryan", "age": 13, "gender": "male"]
dict["hairColor"] = "brown"
Upvotes: 4