On 27.09.2016 12:51, Luis Ferro via swift-users wrote:
let string = "a simple test"
if (string.characters.count > 0) {
let words = string.components(separatedBy: " ")
let headline = words.map { (var word) -> String in
let firstCharacter = word.remove(at: word.startIndex)
return "\(String(firstCharacter).uppercased())\(word)"
}.joined(separator: " ")
}
Swift 3.0 does not support `var` in function/closure parameter list. For
some reason Swift parser didn't catch this as syntax error, I'd suggest you
to report a bug on bugs.swift.org.
This version works:
let string = "a simple test"
if (string.characters.count > 0) {
let words = string.components(separatedBy: " ")
let headline = words.map { wordParam -> String in //<<< immutable
var word = wordParam //<<< assign to mutable instance
let firstCharacter = word.remove(at: word.startIndex)
return "\(String(firstCharacter).uppercased())\(word)"
}.joined(separator: " ")
}
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users