Author Topic: Fixing the "Cannot invoke count with an argument list of type String" in Swift 2  (Read 6604 times)

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
In Swift 2.0, you no longer use the count() free function to count the characters in a string. You call the count() method on the String's character property instead.

For example, the following code uses the count() function to count the characters in a label's text property:

Code: [Select]
let i = count(self.lblWinnerText.text!)
This should be changed to:

Code: [Select]
let i = self.lblWinnerText.text!.characters.count
All the best!
Kevin McNeish
Author of Learn to Code in Swift: https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11
Check out our Robot Tic-Tac-Toe app: https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8
« Last Edit: November 11, 2015, 12:14:55 PM by kjmcneish »