[英]Swift func - Does not conform to protocol “Boolean Type”
Yes it's man vs compiler time and the compiler winning yet again! 是的,这是人与编译器的时间,编译器又赢了! In the func getRecordNumber I am returning a Bool and a Dictionary
在func getRecordNumber中,我返回一个布尔和一个字典
func getRecordNumber(recordNumber: Int32) -> (isGot: Bool, dictLocations: Dictionary <String, Double>)
...
return (isGot, dictLocations)
However after I have called the func and question the Boolean isGot return I get the error message 但是,在我调用了func并询问布尔isGot返回值之后,我得到了错误消息
(isGot: Bool, dictLocations: Dictionary <String, Double>) Does not conform to protocol "Boolean Type"
Any ideas what I have left out? 有什么想法我遗漏了吗?
You don't need to add parameters into return like this (isGot: Bool, dictLocations: Dictionary <String, Double>)
. 您不需要像这样向return中添加参数
(isGot: Bool, dictLocations: Dictionary <String, Double>)
。 you just need to tell compiler that what type this function will return. 您只需要告诉编译器此函数将返回哪种类型。
Here is the correct way to achieve that: 这是实现该目标的正确方法:
func getRecordNumber(recordNumber: Int32) -> (Bool, Dictionary <String, Double>)
{
let isGot = Bool()
let dictLocations = [String: Double]()
return (isGot, dictLocations)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.