not good but great

プログラミング、アート、映画・本の感想について書きます。

Trailing closure syntaxを使ってsplitのisSepalatorを省略する

let num = "one,two,three"

//["one", "two", "three"]
let array = split(num){ $0 == "," }

SwiftではcomponentsSeparatedByStringではなく、splitで文字列を分割することができる。またTrailing closure syntaxを使って、isSepalatorを省略することもできる。

swift - split now complains about missing "isSeparator" - Stack Overflow

Closures — The Swift Programming Language (Swift 5.6)