Confusion about return type of evaluate(_ trust: SecTrust, forHost host: String)

Hi, can someone here explain to me why

    /// - Returns: A `Bool` indicating whether the evaluator considers the `SecTrust` value valid for `host`.
    func evaluate(_ trust: SecTrust, forHost host: String) throws

(from Alamofire/ServerTrustEvaluation.swift at master · Alamofire/Alamofire · GitHub) is correct? AFAIK a function without a defined return type returns Void, not Bool...

Success is simply defined as the absence of an error, so there's no need for a return value. If I returned false from that method, I would need to generate an error, so there's no point, and the error is generated earlier. It does make for a strange feeling API but that's rather unavoidable if you're used to return value handling in these scenarios.

Hi Jon, thanks for the explanation. I'd personally prefer the comment to be worded differently then; but maybe that's just a matter of preference.

Ah, the comment is a bug, leftover from a previous version of the API. Feel free to file a PR.

1 Like