Edward Hasted
Edward Hasted

Reputation: 3423

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(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

(isGot: Bool, dictLocations: Dictionary <String, Double>) Does not conform to protocol "Boolean Type"  

Any ideas what I have left out?

Upvotes: 0

Views: 312

Answers (1)

Dharmesh Kheni
Dharmesh Kheni

Reputation: 71854

You don't need to add parameters into return like this (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)
}

Upvotes: 1

Related Questions