Swift函数 - 不符合协议“布尔类型”
问题描述:
是的,它是人vs编译器时间,编译器再次获胜! 在FUNC getRecordNumber我返回布尔和字典Swift函数 - 不符合协议“布尔类型”
func getRecordNumber(recordNumber: Int32) -> (isGot: Bool, dictLocations: Dictionary <String, Double>)
...
return (isGot, dictLocations)
我已经叫FUNC和质疑布尔但是经过isGot回到我得到错误信息
(isGot: Bool, dictLocations: Dictionary <String, Double>) Does not conform to protocol "Boolean Type"
任何想法我有遗漏了?
答
您不需要像这样返回参数(isGot: Bool, dictLocations: Dictionary <String, Double>)
。你只需告诉编译器该函数将返回什么类型。
这里是实现正确的方法是:
func getRecordNumber(recordNumber: Int32) -> (Bool, Dictionary <String, Double>)
{
let isGot = Bool()
let dictLocations = [String: Double]()
return (isGot, dictLocations)
}