The first step you must do is to have the files referenced in your project. When it appears in red, it means that you have found the files but they are not referenced in the project (probably because you have added them without references or because you have added them from the Finder).
To do this: Right click on the folder where you want to add the file - > Add Files to "MyProject"
Once you have added them you can access them from code in the ViewController.
For reading files I recommend this code extracted from a StackOverflow response (in English)
Swift 3.0
let file = "file.txt" //this is the file. we will write to and read from it
let text = "some text" //just a text
if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
let path = dir.appendingPathComponent(file)
//writing
do {
try text.write(to: path, atomically: false, encoding: String.Encoding.utf8)
}
catch {/* error handling here */}
//reading
do {
let text2 = try String(contentsOf: path, encoding: String.Encoding.utf8)
}
catch {/* error handling here */}
}
For more info:
link