![](/img/trans.png)
[英]Type 'Any' does not conform to protocol 'Equatable' when trying to conform to an equatable generic Set
[英]Type 'String!' does not conform to protocol 'Equatable'
如何在swift iOS 8.0中解決這個問題,即輸入Type 'String!' does not conform to protocol 'Equatable'
Type 'String!' does not conform to protocol 'Equatable'
這是我的代碼
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)
}
我不同意有關簡單升級到最新版本的解決方案的評論。 在進行其他比較之前,使用零檢查解包選項是一種更好的做法 。 我會重寫你的代碼(盡管比需要的更冗長),如下所示,這也應該在所有版本中修復你的問題:
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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.