I've just upgraded to Xcode 16 and my app now fails when attempting to read a text file from the main bundle. It finds the path but can't open the file so this snippet prints: "File read error for path: /private/var/containers/Bundle/Application/AABAD428-96BC-4B34-80B4-97FA80B77E58/Test.app/csvfile.csv"
This worked fine up to 15.4. Has something changed? Thanks.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let bundle = Bundle.main
let path = bundle.path(forResource: "csvfile", ofType: "csv")!
do {
let content = try String(contentsOfFile: path, encoding: String.Encoding.ascii)
} catch {
print("File read error for path: \(String(describing: path))")
}
}
}
Problem solved. In case anyone else has something similar, it looks like Xcode 16 has become more strict in verifying ascii files. The same ascii import has been running on the same text file in my app for years, but now it seems that if there's even a single non-ascii character it gives the "Can't open the file" error. Previously it would just strip out any non-ascii characters and continue to load the file.
I got chatgpt to write me a clever little macro that checks for non-ascii characters in excel and highlights the cells they're in. Turns out there was an eclipse, a smart quote and a few invisible NBSP's which had been copied in from another source many years ago. Replacing those allowed the file to be read again.