-1

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
}
vacawama
  • 150,663
  • 30
  • 266
  • 294
Fred
  • 314
  • 2
  • 7
  • 1
    Please don't link to external code. Stack Overflow questions should be self contained. It's OK to answer your own question, but make sure the code you are presenting shows the original problem. Also, make sure your example is complete. This code is missing definitions for PlaygroundValue among other things. – vacawama Aug 23 '20 at 12:13

1 Answers1

0

Give a data type to the variable may help: Use let dict: [String: PlaygroundValue] = [...] instead of let dict: [:] = [...]

Fred
  • 314
  • 2
  • 7