Initializer for conditional binding must have Optional type, not 'String' on HTTPCookieStorage

540 Views Asked by At

Not sure why I'm getting this error, but I get it when I updated to Swift 2.

The error is on if let token = cookie.value {

Initializer for conditional binding must have Optional type, not 'String'

func saveAuthToken() {
    if let cookies = VPAPICall.sharedInstance.session?.configuration.HTTPCookieStorage?.cookies {
        for cookie in cookies {
            if cookie.name.uppercaseString == "VIEQUES_SESSION_ID" {
                if let token = cookie.value {
}
1

There are 1 best solutions below

0
On BEST ANSWER

It's because cookie.value is not optional, it's type is a String.

You cannot use the if let syntax on non-optional types.

It should be let token = cookie.value, or use .value directly.