Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Emiliano Carrillo
Emiliano Carrillo
1,420 Points

I'm trying to count characters on a textField but it seems that .text or utf16count does´t work anymore. Help please!

I'm trying to make a counter as in twitter but the error says: "apis deprecated as of ios 7 and earlier are unavailable in swift" I have also tried countElements( ) but nope. here is my code...

@IBAction func ContadorCaracteres(sender: AnyObject) {

    var contador = 10 - countElements(sender.text) //neither utf16count
    lblContador.text = "\(contador)"
}

1 Answer

Stone Preston
Stone Preston
42,016 Points

what is this IBAction connected to? what are you trying to access the text property of?

Emiliano Carrillo
Emiliano Carrillo
1,420 Points

It is connected to a textField because I want to count the characters as I write them and as in twitter set a counter on the bottom (with a label) but I don't know how to count the TEXT on the textField

Stone Preston
Stone Preston
42,016 Points

and on what method of the textField is it firing on?

Emiliano Carrillo
Emiliano Carrillo
1,420 Points

mmm... sorry I don´t understand I´m new to this. but I saw a guy who did it like this but it gives me the same error. I want to access to the text of the textField but don't know how :

"sender.text.utf16count"