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

前端 未结 2 1335
小鲜肉
小鲜肉 2020-12-17 08:21

Here is a fun issue I\'m running into after updating to Swift 2.0

The error is on the if let url = URL.absoluteString line

         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 08:30

    absoluteString isn't an optional value, its just a String. You can check if the URL variable is nil

    if let url = yourURLVariable {
        // do your textView function
    } else {
        // handle nil url
    }
    

提交回复
热议问题