Making a dynamic character counter in Swift

User Interaction in ‘Bear Tracker’

On January 18th I decided I wanted to learn to learn the Swift programming language. Since then I’ve spent some 250 hours clearing the hurdles that programming can introduce. ‘Bear Tracker’ has become a way for me to learn all sorts of things about Swift and programming practices in general.

The Character Counter

One of the things I wanted in the ‘Bear Tracker’ I’m working on was the ability to limit the amount of text a user could input into the encounter text field(which is actually a custom textView.. more on that later). At first I did this in a convoluted way — it was passable at the time. But, with some help from a friend, we came to a much cleaner solution.

That’s it! The only code unique to ‘Bear Tracker’ is characterLimit, which is a simple declared variable for the number of characters I want to allow — in this case the famous 140.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.