iOS 8.1上的EXC_BAD_ACCESS与词典 [英] EXC_BAD_ACCESS on iOS 8.1 with Dictionary

查看:144
本文介绍了iOS 8.1上的EXC_BAD_ACCESS与词典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象可以通过一个结构中的静态变量(在现在的swift中缺少类变量支持的解决方法),结构如下:

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有一个字典,如下所示:

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
    }
}

现在首次调用此对象为 Contants.myObj.addParam(param ,value:123) all are well,params has contents [param:123] 。在第二次调用 Contants.myObj.addParam(param,value:456),我得到一个EXC_BAD_ACCESS。

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.

这是踢球者,但只发生在iOS 8.1中。另外,如果我添加行让stupidHack = self.params 作为我的 addParam 方法的第一行,它的作品精细。我的假设是它处理字典的可变性。在初始化之后,let可以以某种方式触发字典再次可变。

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?

谢谢!

推荐答案

看起来像编译器的错误。

Looks like a compiler bug.

您是否尝试过在重新启动和调试之间切换?如果调试工作但不能释放它可能是编译器/优化器错误的指示。

Have you tried switching between Release and Debug then rebuilding? If debug works but not release it can be an indication of a compiler/optimizer bug.

它是否也发生在模拟器中?

Does it happen in the simulator also?

您的代码适用于iOS 8.1和XCode 6.1。

Your code works for me on iOS 8.1 with XCode 6.1.

这篇关于iOS 8.1上的EXC_BAD_ACCESS与词典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆