0

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 {
}
mosaic6
  • 923
  • 3
  • 11
  • 18
  • Did you notice that this is *exactly* the same issue as in one of your older questions [Initializer for conditional binding must have Optional type, not 'String'](http://stackoverflow.com/questions/32768274/initializer-for-conditional-binding-must-have-optional-type-not-string) ? – With a simple lookup of the documentation you could have solved it yourself. – Martin R Sep 29 '15 at 17:49
  • I didn't even realize that. I've got about 200 more errors to get through so I'm not surprised I repeated one. – mosaic6 Sep 29 '15 at 17:55

1 Answers1

3

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.

Benzi
  • 2,439
  • 18
  • 25