swift - xcode 7 cannot assign a value of type '[NSHTTPCookie]' to a value of type '[NSHTTPCookie]' -


i updated xcode7 , trying switch project using swift 2.0 syntax when ran error in file open source library i'm using. here's relevant code:

public lazy var cookies:[string:nshttpcookie] = {     let foundcookies: [nshttpcookie]     if let responseheaders = (self.response as? nshttpurlresponse)?.allheaderfields {         foundcookies = nshttpcookie.cookieswithresponseheaderfields(responseheaders, forurl:nsurl(string:"")!) as! [nshttpcookie]     } else {         foundcookies = []     }     var result:[string:nshttpcookie] = [:]     cookie in foundcookies {         result[cookie.name] = cookie     }     return result     }() 

the error reads: cannot assign value of type '[nshttpcookie]' value of type '[nshttpcookie]'

is there i'm missing here?

change code this:

public lazy var cookies:[string:nshttpcookie] = {   let foundcookies: [nshttpcookie]   if let responseheaders = (self.response as? nshttpurlresponse)?.allheaderfields as? [string:string] {     foundcookies = nshttpcookie.cookieswithresponseheaderfields(responseheaders, forurl:nsurl(string:"")!)   } else {     foundcookies = []   }   var result:[string:nshttpcookie] = [:]   cookie in foundcookies {     result[cookie.name] = cookie   }   return result   }() 

changes:

  • if let responseheaders ... line - did add as? [string:string], because allheadersfields return type [nsobject : anyobject] , not [string:string] required cookieswithresponseheaderfields...

  • removed as! [nshttpcookie] - has no sense, because cookieswithresponseheaderfields return type [nshttpcookie]

just check cookieswithresponseheaderfields signature:

class func cookieswithresponseheaderfields(headerfields: [string : string],   forurl url: nsurl) -> [nshttpcookie] 

please read how ask question. @ least, should point out lines problem is, etc.


Comments