Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 1.2 cannot invoke 'count' with an argument list of type '(String)'

Tags:

swift

xcode6.3

Updated to Xcode 6.3.1 with new Swift 1.2, the old method countElement change to count, however when I switch to use count, it always throw out this error message:

cannot invoke 'count' with an argument list of type '(String)'

This snippet is I copied from Apple doc, but still not working.

func printAndCount(stringToPrint: String) -> Int {
    println(stringToPrint)
    return count(stringToPrint)
}

func printWithoutCounting(stringToPrint: String) {
    printAndCount(stringToPrint)
}

printAndCount("hello, world")
like image 312
goldenlimit Avatar asked Apr 24 '15 18:04

goldenlimit


1 Answers

Try calling the global count function with the Swift module prefix like this:

Swift.count(stringToPoint)

E.g. when extending the Array type there is a property named count as well and thus there is a naming conflict.

like image 74
Klaas Avatar answered Oct 12 '22 01:10

Klaas