I'm trying to follow some very simple code examples, and got this weird
situation with a playground:
//: Playground - noun: a place where people can play
import UIKit
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: " ")
}
This same code inside a func in a class on a normal project will generate a
segmentation fault error on xcode, when compiling the code.
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: " ")
}
···
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: " ")
}
This particular bug has been fixed already on the master branch of Swift, so no need to report it. :-)
Jordan
···
On Sep 27, 2016, at 03:37, Vladimir.S via swift-users <swift-users@swift.org> wrote:
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.