iOS App Development Book/Video Series

General Category => FAQs => Topic started by: kjmcneish on September 12, 2015, 04:18:47 AM

Title: Fixing the "Cannot invoke count with an argument list of type String" in Swift 2
Post by: kjmcneish on September 12, 2015, 04:18:47 AM
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 (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 (https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8)