如何解决Swift Playground编译器错误:编译器无法在合理的时间内对该表达式进行类型检查;
当我编写在SwiftPlayground上运行的代码时,出现了此编译错误:“编译器无法在合理的时间内对该表达式进行类型检查”
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:[:] = [...]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。