Enter "String!" not compliant with equatable protocol

how to resolve this in fast iOS 8.0 ie Type 'String!' does not conform to protocol 'Equatable'

here is my code

func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace?) -> Bool
{
    return protectionSpace?.authenticationMethod == NSURLAuthenticationMethodServerTrust
// Here I got this error near == sign
}

func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge?)
{
    if challenge?.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust
    {
        if challenge?.protectionSpace.host == "www.myhost.com"

// Here I got this error near == sign

        {
            let credentials = NSURLCredential(forTrust: challenge!.protectionSpace.serverTrust)
            challenge!.sender.useCredential(credentials, forAuthenticationChallenge: challenge)
        }
    }

    challenge?.sender.continueWithoutCredentialForAuthenticationChallenge(challenge)
}
+4
source share
1 answer

I do not agree with the comments about a simple upgrade to the latest version for the solution. It is best to deploy zero-check options before other comparisons. I would rewrite your code (albeit a little more verbose than necessary) as follows, which should also fix your problem in all versions:

func connection(connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: NSURLProtectionSpace?) -> Bool
{
    if let authenticationMethod = protectionSpace?.authenticationMethod 
    {
        return authenticationMethod == NSURLAuthenticationMethodServerTrust
    }

    return false
}

func connection(connection: NSURLConnection, didReceiveAuthenticationChallenge challenge: NSURLAuthenticationChallenge?)
{
    if let authenticationMethod = challenge?.protectionSpace.authenticationMethod
    {
        if authenticationMethod == NSURLAuthenticationMethodServerTrust
        {
            if challenge?.protectionSpace.host == "www.myhost.com"
            {
                let credentials = NSURLCredential(forTrust: challenge!.protectionSpace.serverTrust)
                challenge!.sender.useCredential(credentials, forAuthenticationChallenge: challenge)
            }
        }
    }

    challenge?.sender.continueWithoutCredentialForAuthenticationChallenge(challenge)
}
0
source

All Articles