Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Carmen Ibarcena
iOS Development Techdegree Student 8,296 PointsIssue with my code!
Hello All,
i have a question Pasan had give the code for xcode 7 but i still get an error, and I do not know how to fix it
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let length = (textField.text!.characters.count) - range.length + count(String)
}
}
2 Answers

Damien Watson
27,419 PointsHi Carmen,
Due to swift 2, the 'count(string)' also has to change. I have made the update below, also removing the brackets which weren't required:
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let length = textField.text!.characters.count - range.length + string.characters.count
}

Carmen Ibarcena
iOS Development Techdegree Student 8,296 Pointsthank you Daniel Watson! =) I also did it like this func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { let length = textField.text!.characters.count - range.length + string.characters.count }
Damien Watson
27,419 PointsDamien Watson
27,419 PointsOh, and your variable 'string' had a capital 'S'.