Swift 3 warning: Non-optional expression of type 'String' used in a check for optionals

前端 未结 2 1396
一个人的身影
一个人的身影 2021-01-11 16:14

I\'m updating a project to Swift 3 and came across the following warning which I can\'t seem to resolve.

fileprivate var filteredTitlesList: [String] = []

i         


        
相关标签:
2条回答
  • 2021-01-11 16:42

    Other possibility of this warning is when you're trying to put a statement eg:let keyboardFrame: CGRect = keyboardFrameValue.cgRectValue in conditional statement like if or guard

    0 讨论(0)
  • 2021-01-11 16:47

    You are trying to unwrap a value that is already unwrapped, and hence you are getting an error because it doesn't need unwrapping again. Change your if statement to look like the following and you should be golden:

    if filteredTitleList.count > indexPath.row {
        let filteredTitle = filterdTitleList[indexPath.row]
    }
    

    Unfortunately there is no way to bind the variable within the if statement, hopefully they'll add one in the future.

    0 讨论(0)
提交回复
热议问题