Bundle.main.path(forResource:ofType:inDirectory:) returns nil
Double check the Options
in the add files
menu when adding the file. The target in Add to targets
must be ticked to add it to the bundle:
In case you are actually in another bundle (test for instance), use:
guard let fileURL = Bundle(for: type(of: self)).url(forResource: fileName withExtension:"txt") else { fatalError("File not found")}