I downloaded this code from hackingwithswift.com, but it always fails at loading the file. Does anyone have an idea what might cause this problem? Here's my code:
Code Block swift if let filepath = Bundle.main.path(forResource: "german", ofType: "dic") { do { contents = try String(contentsOfFile: filepath) print(contents) } catch { print("contents could not be loaded") } } else { print("file not found") } text = contents.components(separatedBy: "\n")
The file german.dic is surely added to your project? (File names are case-sensitive in iOS.)
Does it exist in the flat place? (Meaning not under a Folder which is bundled as a directory)
The Target Membership is checked? (Shown in the File Inspector at the right hand of Xcode window.)