iOS 8.1上的EXC

编程入门 行业动态 更新时间:2024-10-26 09:30:29
本文介绍了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

本文发布于:2023-11-26 12:33:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633939.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:iOS   EXC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!