Reputation: 92
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")
Upvotes: 7
Views: 4150
Reputation: 1199
I had the same problem and it was making me crazy.
To solve it, I used:
myString.characters.count
Bingo.
Upvotes: 2
Reputation: 22773
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.
Upvotes: 4
Reputation: 137
Did you declare the variable "count" in the same scope? If so, you should change the variable name. And try to build again.
Upvotes: 3
Reputation: 92
Well, I create a new playground and copy the code works fine. I guess it's because the previous playground swift version messed up. Create a new project works fine.
Upvotes: -1