This series was made on Xcode 9 and Swift 4. Swift 4 has provided range bridging. You’ll have to do some digging to translate to Swift 3. You can also check out the older version of this course which was made in Swift 3 over here:
Hi, I have done everything like in the video, but the doneBarButton is still enabled. Only in keyboard is disabled when textField is empty, but the actual button it’s not changing.
If the button is still being disabled, then there is still a string present in newText. My suggestion: before the isEmpty check, print out the results of newText. My guess is that it contains a space character. So it would look something like this: " "
Play around with it and let me know what you discover.
sorry for interrupting again, but I didn’t understand for what do we need this piece of code:
let oldText = textField.text!
let stringRange = Range(range, in: oldText)
let newText = oldText.replacingCharacters(in: stringRange!, with: string)
In the video you said that it allows user to copy and paste text, but what actually this code does?
Thanks
It wasn’t really explained in the video. Basically, this code checks to see if there is any text that the user is typing into the text field and compares against the old values. If it’s empty, then you know that the user may have selected all, and deleted everything or just backspaced until everything was gone.