Created
November 21, 2016 17:52
-
-
Save rsfinn/984ad704e7935335fada11264690b818 to your computer and use it in GitHub Desktop.
Swift 3 `String` extension to convert text file contents to lines, even if file is DOS format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
func separatedIntoLines() -> [String] { | |
var lines: [String] = [] | |
let wholeString = self.startIndex..<self.endIndex | |
self.enumerateSubstrings(in: wholeString, options: .byLines) { | |
(substring, range, enclosingRange, stopPointer) in | |
if let line = substring { | |
lines.append(line) | |
} | |
} | |
return lines | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment