Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 使用Vapor时,当模型是类时,Xcode不会停止索引_Swift_Xcode_Vapor - Fatal编程技术网

Swift 使用Vapor时,当模型是类时,Xcode不会停止索引

Swift 使用Vapor时,当模型是类时,Xcode不会停止索引,swift,xcode,vapor,Swift,Xcode,Vapor,当符合vapor中一个类的模型协议时,我提出了这样一个类: import Foundation import Vapor import Fluent struct Intubation: Model { var exists: Bool = false var id: Node? var intubationID: String var residentName: String var residentSpec: String var date:

当符合vapor中一个类的模型协议时,我提出了这样一个类:

import Foundation
import Vapor
import Fluent

struct Intubation: Model {
    var exists: Bool = false
    var id: Node?
    var intubationID: String
    var residentName: String
    var residentSpec: String
    var date: String
    var attending: String
    var PGY: String
    var medical: String?
    var technique: String
    var reason: String
    var dlifOverall: String
    var dsfOverall: String
    var dpfOverall: String
    var dvfOverall: String
    var dsafOverall: String
    var lowOxySatBefore: Int
    var lowOxySatDuring: Int
    var lowOxySatAfter: Int
    var lowSysBpBefore: Int
    var lowSysBpDuring: Int
    var lowSysBpAfter: Int
    var intubationOverall: String
    var comments: String


init(intubationID: String, date: String, residentName: String, residentSpec: String, attending: String, PGY: String, medical: String? = nil, technique: String, reason: String, dlifOverall: String, dsfOverall: String, dpfOverall: String, dvfOverall: String, dsafOverall: String, intubationOverall: String, comments: String, lowOxySatBefore: Int, lowOxySatDuring: Int, lowOxySatAfter: Int, lowSysBpBefore: Int, lowSysBpDuring: Int, lowSysBpAfter: Int) {

    self.intubationID = intubationID
    self.date = date
    self.residentName = residentName
    self.residentSpec = residentSpec
    self.attending = attending
    self.PGY = PGY
    self.medical = medical
    self.technique = technique
    self.reason = reason
    self.dlifOverall = dlifOverall
    self.dsfOverall = dsfOverall
    self.dpfOverall = dpfOverall
    self.dvfOverall = dvfOverall
    self.dsafOverall = dsafOverall
    self.intubationOverall = intubationOverall
    self.comments = comments
    self.lowSysBpAfter = lowSysBpAfter
    self.lowOxySatAfter = lowOxySatAfter
    self.lowSysBpBefore = lowSysBpBefore
    self.lowOxySatBefore = lowOxySatBefore
    self.lowSysBpDuring = lowSysBpDuring
    self.lowOxySatDuring = lowOxySatDuring
}

init(node: Node, in context: Context) throws {
    id = try node.extract("id")
    intubationID = try node.extract("intubationID")
    date = try node.extract("date")
    residentName = try node.extract("residentName")
    residentSpec = try node.extract("residentSpec")
    attending = try node.extract("attending")
    PGY = try node.extract("PGY")
    medical = try node.extract("medical")
    technique = try node.extract("technique")
    reason = try node.extract("reason")
    dlifOverall = try node.extract("dlifOverall")
    dsfOverall = try node.extract("dsfOverall")
    dpfOverall = try node.extract("dpfOverall")
    dvfOverall = try node.extract("dvfOverall")
    dsafOverall = try node.extract("dsafOverall")
    intubationOverall = try node.extract("intubationOverall")
    comments = try node.extract("comments")
    lowSysBpAfter = try node.extract("lowSysBpAfter")
    lowOxySatAfter = try node.extract("lowOxySatAfter")
    lowSysBpBefore = try node.extract("lowSysBpBefore")
    lowOxySatBefore = try node.extract("lowOxySatBefore")
    lowSysBpDuring = try node.extract("lowSysBpDuring")
    lowOxySatDuring = try node.extract("lowOxySatDuring")
}


func makeNode(context: Context) throws -> Node {
    return try Node(node: ["id": id,
                           "intubationID": intubationID,
                           "residentName": residentName,
                           "residentSpec": residentSpec,
                           "attending": attending,
                           "PGY": PGY,
                           "medical": medical,
                           "technique": technique,
                           "reason": reason,
                           "dlifOverall": dlifOverall,
                           "dsfOverall": dsfOverall,
                           "dpfOverall": dpfOverall,
                           "dvfOverall": dvfOverall,
                           "dsafOverall": dsafOverall,
                           "intubationOverall": intubationOverall,
                           "comments": comments,
                           "lowSysBpAfter": lowSysBpAfter,
                           "lowOxySatAfter": lowOxySatAfter,
                           "lowSysBpBefore": lowSysBpBefore,
                           "lowOxySatBefore": lowOxySatBefore,
                           "lowSysBpDuring": lowSysBpDuring,
                           "lowOxySatDuring": lowOxySatDuring])
}

static func prepare(_ database: Database) throws {
    try database.create("intubations") { intubations in
        intubations.id()
        intubations.string("intubationID")
        intubations.string("residentName")
        intubations.string("residentSpec")
        intubations.string("attending")
        intubations.string("PGY")
        intubations.string("medical")
        intubations.string("technique")
        intubations.string("reason")
        intubations.string("dlifOverall")
        intubations.string("dsfOverall")
        intubations.string("dpfOverall")
        intubations.string("dvfOverall")
        intubations.string("dsafOverall")
        intubations.string("intubationOverall")
        intubations.string("comments")
        intubations.int("lowSysBpAfter")
        intubations.int("lowOxySatAfter")
        intubations.int("lowSysBpBefore")
        intubations.int("lowOxySatBefore")
        intubations.int("lowSysBpDuring")
        intubations.int("lowOxySatDuring")
    }
}

static func revert(_ database: Database) throws {
    try database.delete("intubations")
}


}

此代码不允许Xcode完成索引。它被卡住了,没有完成,也没有编译,因为它正忙于索引然而如果它被标记为
结构
而不是
,那么它将编译并且Xcode完成索引

这是一个不时出现的问题,我将尽力解释

node之所以能够以这种方式使用字典文本,是因为存在大量泛型重载和推理。不幸的是,这会成倍地增加编译时间,有时甚至导致编译不可能

在Vapor2(目前在alpha中)中,我们做了一些工作来加强这一点,并让用户更加清楚。现在,让我们来解决手头的问题

按如下方式分解makeNode函数:

var node = Node.object([:])
node["key"] = try value.makeNode()
// .. continue
return node
这是一个稍微长一点的表单,但对编译器有很大帮助

蒸汽2

它还没有发布,但当我在这里的时候,答案不会过时。(上面的代码仍然有效!)

var node = Node([:])
try node.set("key.path", value)
// ... continue
return node