【问题标题】:Playground(Swift) Excecution was interrupted issuePlayground(Swift)执行被中断问题
【发布时间】:2015-03-29 14:11:40
【问题描述】:

同一段代码无法在 Playground 上运行,但可以在 xcode 项目中运行。

出现错误“执行被中断。原因:EXC_BAD_INSTRUCTION....”

这是详细截图

这里的问题是弄清楚为什么会发生这个问题?为什么存在于游乐场而不存在于 xcode 中?

谢谢

【问题讨论】:

    标签: ios swift swift-playground int32


    【解决方案1】:

    当我在操场上编写相同的代码时(Xcode 版本 6.1.1 (6A2008a)),出现错误:"Use of unresolved identifier 'rand'"

    游乐场只是一个“游乐场”,不要太认真。我也对一些非常奇怪的问题感到困惑,即代码在正常的 Xcode 项目上工作,但在操场上不能很好地工作。 Apple 仍然需要提高 Playground 的稳定性,虽然它很酷。

    【讨论】:

      【解决方案2】:

      你没有初始化inputArray[i]。分配给不存在的数组元素会崩溃。相反(我猜),通过

      附加值
      inputArray.append(Int(rand())
      

      当然,它也会在代码中崩溃,而不仅仅是在 Playground 中。

      作为旁注。写

      var inputArray = [Int]() // init as used by Apple now with trailing braces
      for i in 0..<10 { // use range instead
        inputArray.append(Int(rand())
      }
      

      更迅速地拥有它。

      【讨论】:

        猜你喜欢
        • 2021-02-18
        • 1970-01-01
        • 2017-12-26
        • 1970-01-01
        • 1970-01-01
        • 2017-02-25
        • 1970-01-01
        • 2017-05-06
        • 1970-01-01
        相关资源
        最近更新 更多