简体   繁体   中英

Swift Playground Compiler Error: The compiler is unable to type-check this expression in reasonable time;

When I was writing code running on SwiftPlayground, I got this compiling error: "The compiler is unable to type-check this expression in reasonable time"

public func toPlaygroundValue() -> PlaygroundValue {
    let dict: [:] = [
        "pitch": .floatingPoint(Double(pitch)),
        "roll":  .floatingPoint(Double(roll)),
        "yaw":   .floatingPoint(Double(yaw)),
        "vgx":   .floatingPoint(Double(vgx)),
        "vgy":   .floatingPoint(Double(vgy)),
        "vgz":   .floatingPoint(Double(vgz)),
        "tof":   .floatingPoint(Double(tof)),
        "h":     .floatingPoint(Double(h)),
        "bat":   .integer(bat),
        "baro":  .floatingPoint(Double(baro)),
        "time":  .floatingPoint(Double(time)),
        "agx":   .floatingPoint(Double(agx)),
        "agy":   .floatingPoint(Double(agy)),
        "agz":   .floatingPoint(Double(agz)),
        "marker": PlaygroundValue.dictionary([
            "id":   .integer(marker.id),
            "x":  .floatingPoint(Double(marker.x)),
            "y":  .floatingPoint(Double(marker.y)),
            "z":   .floatingPoint(Double(marker.z)),
        ]),
        "temp": PlaygroundValue.dictionary([
            "temph":   .integer(temp.temph),
            "templ":   .integer(temp.templ),
        ]),
        "mpry":PlaygroundValue.dictionary([
            "x":  .floatingPoint(Double(mpry.x)),
            "y":  .floatingPoint(Double(mpry.y)),
            "z":   .floatingPoint(Double(mpry.z)),
        ]),
        "sn": .string(sn),
    ]
    let value: PlaygroundValue = PlaygroundValue.dictionary(dict)
    return value
}

为变量指定数据类型可能会有所帮助:使用 let dict: [String: PlaygroundValue] = [...] 而不是 let dict: [:] = [...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM