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


  • 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:
Check out our Robot Tic-Tac-Toe app:
« Last Edit: November 11, 2015, 12:14:55 PM by kjmcneish »