Swift编译器2.1.1永远挂在字典

时间:2016-02-10 20:59:30

标签: swift xcode hang sourcekitservice grdb

我正在为sqlite library构建一个类,突然编译器永远挂起。

我终于得到了一个测试用例,发现它与字典解析有关。这是最小的代码:

导入基金会 导入GRDB

class DeudaCliente : Record {
    var id: Int64
    var codigo: String
    var nombre: String
    var cobro: String
    var direccion: String
    var telefono: String
    var orden: Int32
    var calificacion: String
    var fechaIngreso: NSDate
    var fecha: NSDate
    var capital: NSDecimalNumber
    var interes: NSDecimalNumber
    var cuota: NSDecimalNumber
    var valor: NSDecimalNumber
    var valorPagar: NSDecimalNumber
    var saldo: NSDecimalNumber
    var atrasados: Int32


    /// Initialize from a database row
    required init(_ row: Row) {
        id = row.value(named: "id")
        codigo = row.value(named: "codigo")
        nombre = row.value(named: "nombre")
        cobro = row.value(named: "cobro")
        direccion = row.value(named: "direccion")
        telefono = row.value(named: "telefono")
        orden = row.value(named: "orden")
        calificacion = row.value(named: "calificacion")
        fechaIngreso = row.value(named: "fechaIngreso")
        fecha = row.value(named: "fecha")
        interes = row.value(named: "interes")
        cuota = row.value(named: "cuota")
        valor = row.value(named: "valor")
        valorPagar = row.value(named: "valorPagar")
        saldo = row.value(named: "saldo")
        capital = row.value(named: "capital")
        atrasados = row.value(named: "atrasados")

        super.init(row)
    }

    /// The values persisted in the database
    override var persistentDictionary: [String: DatabaseValueConvertible?]
    {
        return  [
            "id": id,
            "nombre": nombre,
            "codigo": codigo,
            "cobro": cobro,
            "direccion": direccion,
            "telefono": telefono,
            "orden": orden,
            "calificacion": calificacion,
            "fechaIngreso": fechaIngreso,
            "fecha": fecha, //THE COMPILER SLOWDOWN HERE
            "interes": interes,
            "cuota": cuota, //THE COMPILER HANG HERE
            "valor": valor,
            "valorPagar": valorPagar,
            "saldo": saldo,
            "capital": capital,
            "atrasados": atrasados
        ]
    }
}

奇怪的是我在关键字" fecha"之后更改了值。对于像1," a"等标量,编译工作。

另外:索引在" cuota"之后也会永远存在。并且服务 SourceKitService 开始报告+ 300%CPU,增加内存(我有数到6GB)

这是关于El capitan,xcode版本7.2.1(7C1002)

1 个答案:

答案 0 :(得分:0)

我是GRDB的作者。在https://github.com/groue/GRDB.swift/issues/21

上阅读我的回答

我猜这个字典对于Swift编译器来说太长了。你可以尝试打破它,或者在密钥之后构建密钥,如:

var dic: [String: DatabaseValueConvertible?] = [:]
dic["id"] = id
dic["nombre"] = nombre
// etc.
return dic