[swift-users] xcode8 segmentation fault help

Vladimir.S svabox at gmail.com
Tue Sep 27 05:37:54 CDT 2016


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: " ")
}


More information about the swift-users mailing list