I'm using the function String.withCString()
as follows:
let s = "Hey!"let c = s.withCString { strlen($0)}println(c)
However, if I add a second line to the withCString closure, I get an error
let s = "Hey!"let c = s.withCString { println("test") strlen($0)}println(c)
The error is: "Cannot convert the expression's type '(($T4) -> $T3) -> (($T4) -> $T3) -> $T3' to type 'Result'.
Looking at the declaration for withCString
it says:
func withCString<Result>(f: (UnsafePointer<Int8>) -> Result) -> Result
Which I have been interpreting as saying that the f
parameter will be a function that takes an UnsafePointer<Int8>
as input and returns some type as a result. This is what my second example is doing. What's wrong with the second example block?