I have a string that I got from a text file.
Text file:
Line 1 Line 2 Line 3 ...
I want to convert it to an array, one array element p
in Xcode 8.2, Swift 3.0.1:
Use NSString method components(separatedBy:)
let text = "line1\nline2" let array = text.components(separatedBy: CharacterSet.newlines)
Or use String method enumerateLines, like Leo Dabus's answer
Leo Dabus