Trying to read a text file 1 line at a time and append each line to string array “text”
Button(“Read File”) {
let path = Bundle.main.path(forResource: “TextFile”, ofType: “txt”)!
let text = try! String(contentsOfFile: path, encoding: String.Encoding.utf8)
let range = text.startIndex ..< text.endIndex
var lines = [String]()
text.enumerateSubstrings(in: range, options: String.EnumerationOptions.byLines) {
(substring, range, enclosingRange, stop) in
guard let substring = substring else { return }
lines.append(substring)
}
n4 = text[0] Cannot assign value of type Character tp type string
at the top I have @State var n4 = “”