细分错误Xcode 11

时间:2019-09-23 14:40:06

标签: swift xcode xcode11

序列化“ AnyArrayBox”时出现分段错误

  1. 正在运行#0 SILModuleTransform“ SerializeSILPass”。
  2. 序列化“ AnyArrayBox”时(在“模块”模块中) 0迅速0x000000010d7abeb3 PrintStackTraceSignalHandler(void *)+ 51 1快速0x000000010d7ab686 SignalHandler(int)+ 358 2 libsystem_platform.dylib 0x00007fff76c31b5d _sigtramp + 29

这是AnyArray结构

    struct AnyArray<Element>: RandomAccessCollection {

    typealias Index = Int

    private let box: AnyArrayBase<Element>

    init<Concrete: RandomAccessCollection>(_ concrete: Concrete) where Concrete.Element == Element, Concrete.Indices == Indices {
        box = AnyArrayBox(concrete)
    }

    var startIndex: Int { return box.startIndex }
    var endIndex: Int { return box.endIndex }

    func index(after i: Int) -> Int {
        return box.index(after: i)
    }

    subscript(position: Index) -> Element {
        return box[position]
    }

}

还有另外两个在其中使用

private class AnyArrayBase<Element>: RandomAccessCollection {

    init() {
        guard type(of: self) != AnyArrayBase.self else {
            fatalError("_AnyArrayBase<Element> is an abstract class, it can not be created; create subclass instance instead")
        }
    }

    typealias Index = Int

    var startIndex: Int { fatalError("Must override") }
    var endIndex: Int { fatalError("Must override") }

    func index(after i: Int) -> Int {
        fatalError("Must override")
    }

    subscript(position: Index) -> Element {
        fatalError("Must override")
    }

}

private final class AnyArrayBox<Concrete: RandomAccessCollection>: AnyArrayBase<Concrete.Element> where Concrete.Indices == AnyArrayBase<Concrete.Element>.Indices {

    private let concrete: Concrete

    init(_ concrete: Concrete) {
        self.concrete = concrete
    }

    override var startIndex: Int { return concrete.startIndex }
    override var endIndex: Int { return concrete.endIndex }

    override func index(after i: Int) -> Int {
        return concrete.index(after: i)
    }

    override subscript(position: Index) -> Element {
        return concrete[position]
    }

}

我该如何解决?有什么建议吗?

2 个答案:

答案 0 :(得分:2)

这有效

var dim_values : (dim1:String?,dim2:String?,dim3:String?) = (nil, nil, nil)

显然,编译器需要显式初始化(​​到nil)

答案 1 :(得分:0)

当移至Xcode 11.0(11A420a)时,我遇到了同样的问题 它指向我在其中将元组作为结构的一部分的一行:

var dim_values : (dim1:String?,dim2:String?,dim3:String?) 

我将其更改为另一种结构,并解决了该问题。