I'm loading .txt files onto a tableview and for the larger files, there is a lag of a noticeable second or 2 before the textview loads with the .txt file. Is there a way to quick load the first x number of lines immediately and then the rest of the file at the normal pace so I can get rid of that 1 second delay?
The files are in my bundle as .txt files.
They are loaded into UITableView like so:
let storyNames = [ "story7", "story3", "story4", "story8", "story11", "story9", "story12", "story2", "story5", "story6", "story1", "story10" ]
let stories = storyNames.compactMap {
story in
return Bundle.main.url(forResource: storyName, withExtension: "txt")
}
... tableview methods to print at cellForRowAt
Passed onto DetailTextView like:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let vc = storyboard?.instantiateViewController(withIdentifier: "DetailTextView") as? DetailTextViewController {
vc.selectedStory = stories[indexPath.row]
navigationController?.pushViewController(vc, animated: true)
}
}
And then printed in the DetailTextView:
let storyText = try? String(contentsOf: selectedStory)
textView.text = storyText