自变异枚举函数出错

时间:2018-03-03 02:38:05

标签: swift enums malloc

当我用更大的枚举实例替换枚举时,我似乎遇到了错误。它可以作为一个快速的游乐场运行,但当我在iOS设备上运行时,我收到malloc错误:

enum E {
  case small
  case big(foo:[Int])
  mutating func swap(with e:E) {
    self = e //malloc: *** error for object 0x13805d000: incorrect checksum for freed object - object was probably modified after being freed.
  }
}

var i = [Int](1...100000)
var a = E.small
var b = E.big(foo:i)
a.swap(with:b)

为什么行self = e会出现运行时错误?

0 个答案:

没有答案