【发布时间】:2014-08-10 08:32:59
【问题描述】:
我正在关注RW tutorial to learn about Swift,但在以下函数声明的第一行出现错误:
func returnPossibleTips() -> [Int: Double] {
let possibleTipsInferred = [0.15, 0.18, 0.20]
let possibleTipsExplicit:[Double] = [0.15, 0.18, 0.20]
var retval = [Int: Double]()
for possibleTip in possibleTipsInferred {
let intPct = Int(possibleTip*100)
retval[intPct] = calcTipWithTipPct(possibleTip)
}
return retval
}
这些是错误:
- 函数结果的预期类型
- 一行中的连续声明必须用';'分隔
- 预期声明
- 函数声明体中应为“{”
【问题讨论】:
-
您的代码在我的测试项目中编译良好(当我删除未知函数 calcTipWithTipPct 时)。我认为您应该在函数实现之外搜索语法错误