I have an object accessible via a static var in a struct (workaround for the lack of class variable support in swift right now), structured like this:
struct Constants{
static var myObj = MyObject()
}
MyObject has a dictionary in it like so:
class MyObject{
private var params = Dictionary<String,AnyObject>()
func addParam(key:String, value:AnyObject){
params[key] = value
}
}
Now on the first call to this object for Contants.myObj.addParam("param", value:123)
all is well and params has contents ["param":123]
. On the second call for Contants.myObj.addParam("param", value:456)
, I get a EXC_BAD_ACCESS.
Here's the kicker though, this only occurs in iOS 8.1. Also, if I add the line let stupidHack = self.params
as the first line of my addParam
method, it works fine. My assumption is that it deals with mutability of dictionaries. The let may somehow trigger the dictionary to be mutable again after initialization.
Has anyone else run into this issue before? Any idea on how to fix it?
Thanks!