简体   繁体   English

Swift func-不符合协议“布尔类型”

[英]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.

相关问题 错误:类型“ UserAccView”不符合协议“ UITableViewDataSource” - error : type “UserAccView” does not conform to protocol 'UITableViewDataSource' Swift-使func类型显式(在协议中) - Swift - Make func type explicit (in protocol) 在 Swift 中,如何声明一个字典,其中键是一个函数? (不符合协议&#39;Hashable&#39;) - In Swift, How can I declare a Dictionary where the key is a function? (does not conform to protocol 'Hashable') Swift-参数必须符合协议且检查为kindOf的函数 - Swift - Function where parameter must conform to protocol and check is kindOf 如何使用 boolean 设置功能? - how to set func with boolean? Swift:将函子传递给函子称为传递的函子 - Swift: passing a func into a func calls the passed in func 如何使用 enum、func 和 switch 以便它接收数据类型“月”并返回 swift 上的月份数? - How can I use enum, func and switch so that it receives a data type “month” and returns the numer of the month on swift? swift 函数和闭包可以符合 Hashable 吗? - can swift functions and closures conform to Hashable? Swift中带有参数的静态函数选择器? - Selector to Static Func with Parameters in Swift? Swift 函数在预期后调用 - Swift Func called after expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM