Here is what I've tried
var villages = [NSDictionary]()
var bars = [NSMutableDictionary]()
var allBars = [NSMutableDictionary]()
(bars[2]).setObject(distanceInMiles, forKey: "Distance" as NSCopying)
//And this
bars[2]["Distance"] = distanceInMiles
There is no distance field in my dictionary currently but I'd like to add it to the dictionary and set the value for it.
I keep getting this error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'
Here is how my dictionary is laid out:
[{
Latitude = "40.719629";
Longitude = "-74.003939";
Name = "Macao Trading Co";
ObjectID = ayORtpic7H;
PlaceID = ChIJA9S9jIpZwokRZTF0bHWwXYU;
}, {
Latitude = "40.717304";
Longitude = "-74.008571";
Name = "Bar Cyrk";
ObjectID = z7NV2uOmgH;
PlaceID = ChIJaWlspR9awokRvrKEAoUz3eM;
}, {
Latitude = "40.720721";
Longitude = "-74.005489";
Name = "AOA Bar & Grill";
ObjectID = GIst3BLb5X;
PlaceID = ChIJBYvf3IpZwokRJXbThVSI4jU;
}]
I'm not sure what I'm doing wrong. My bars dictionary is mutable so why do I keep getting the mutating method sent to immutable object error?