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

iOS Delegates in Swift 2 Delegation in iOS Modifying Behavior With Delegates

Twinnie Ting
PLUS
Twinnie Ting
Courses Plus Student 2,441 Points

Why did we do this to count the length: let length = count(textfield.text) - range.length + count(string)

The scenario was to count the length in the textfield: Why do we have to subtract range.length and then add count(string) to this formula, when we can just say count(textfield.text)?

1 Answer

strings are made of chars yet not all chars are the same size thanks to emoji I believe the expression you have endeavors to remove the effect of this and count true characters

you answer is somewhere in here http://stackoverflow.com/questions/24037711/get-the-length-of-a-string