Chapter 12 p 275 - Expected expression after operator error

Hi,

When I add the following to AddItemViewController.swift, I have on the line “let stringRange = Range(…)” the “Expected expression after operator”. I don’t get why. I compared with the files from the book, still don’t catch the mistake.

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    
    let oldText = textField.text !
    let stringRange = Range(range, in:oldText)!
    let newText = oldText.replacingCharacters(in: stringRange, with: string)
    
    if newText.isEmpty {
        doneBarButton.isEnabled = false
    }else {
        doneBarButton.isEnabled = true
    }
    return true
    
}

Any ideas ?

Found it ! There is an additional space in the “let oldText” line…

@nidupb Thank you for the update. Really glad you managed to fix it.

This topic was automatically closed after 166 days. New replies are no longer allowed.