I think you should debug firstly, can you catch the file and then can you use it. If all statements are working, can you provide more codes to explain it ?
func startGame() {
// Check if the file "start.txt" exists in the main bundle
if let startWordsURL = Bundle.main.url(forResource: "start", withExtension: "txt") {
print("File found: \(startWordsURL)") // Debugging statement
do {
// Try to read the content of the file
let startWords = try String(contentsOf: startWordsURL, encoding: .utf8)
let allWords = startWords.components(separatedBy: "\n")
// Debugging statement to print all words loaded from the file
print("Words loaded: \(allWords)")
// If you want to set a random word as the rootWord
// rootWord = allWords.randomElement() ?? "november"
} catch {
// If there's an error reading the file, print the error
print("Error reading file: \(error)")
}
} else {
// If the file wasn't found, print a message
print("File 'start.txt' not found in the bundle.")
}
}