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 Implementing a Login Screen with Delegates

Implementing a Login Screen with Delegates

so when I open the file in my Xcode, the Login screen has a code error which is preventing me from following along with the video.

In this part of the code:

''' swift

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { let length = count(textField.text) - range.length + count(string) if length > 0 { submitButton.enabled = true } else { submitButton.enabled = false } return true } '''

there is an error on the line

let length = count(textField.text) - range.length + count(string)

which tells me "cannot invoke 'count' with an argument list of type (String?)"

I can't seem to figure out how to work this out, any help would be appreciated. Thanks!

2 Answers

It seems that you can no longer call the count function and instead it is a property on textField in Xcode 7. You need to change it to:

let length = textField.text!.characters.count - range.length + string.characters.count
Anthony Boutinov
Anthony Boutinov
13,844 Points

Xcode 7.3 is smart enough now to fix that issue all by itself upon opening the project for the first time.