Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// New `joined` and `split` functions in Swift 4.1
// More info at Swift [Array Documentacion](
import Foundation
// The sample data...
let data: [String] = [ "Col1", "Col2", "Col3", "Col4", "Col5"]
// Export data to CSV format
let csv: String = data.joined(separator: ";")
// Result: Col1;Col2;Col3;Col4;Col5
// Convert a string in an array
// map function in order to convert ArraySlice items to String
let backToData: [String] = csv.split(separator: ";").map(String.init)
// Result: ["Col1", "Col2", "Col3", "Col4", "Col5"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.