I'm trying to read text document file with lines in random order after button is pressed. So far I've managed to write a code to read lines with button and display it in label. But problem is that it displays one word and if I click it again it does nothing. Although file is full of words. Solution would be helpful and also code to read lines in random order. Here's my code:
class BeginAfter: UIViewController {
@IBOutlet weak var word: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func Correct(){
if let path = Bundle.main.path(forResource: "words", ofType: "txt") {
do {
let data = try String(contentsOfFile: path, encoding: .utf8)
let myStrings = data.components(separatedBy: .newlines)
word.text = myStrings.joined(separator: "\n")
} catch {
print(error)
}
}
}
}