I have several locally saved .txt files that are loaded and saved as a URL array like:
func loadShortStories() {
shortStories = Bundle.main.urls(forResourcesWithExtension: "txt", subdirectory: nil)!
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destinationViewController = segue.destination as? ListVC {
destinationViewController.shortStories = shortStories
}
}
And then in the next ListVC where I load them into a tableview, I have:
var shortStories: [URL] = []
I need to hardcode the specific order of the .txt files but need to convert them to a string first. How can I do this?
I tried
let shortStoriesString = shortStories.absoluteString but it does not work.
Added:
I do remove pathextension and lastcomponent in cellForRowAt method with:
shortStories[indexPath.row].deletingPathExtension().lastPathComponent
But before I do that, I want to hardcode the order in which the .txt files are being loaded into the textview because its random and I would like them to be listed in a specific non algorithmic way, like:
let order : [String] = [ "story7.txt", "story3.txt", "story1.txt", "story4.txt" ]
. That's why I am trying to convert the URL into a string.
FileManager.default.displayName(atPath: yourURL.path)or get your url resourceValues for the localizedNameKeyurls.sorted { $0.lastPathComponent < $1.lastPathComponent }orurls.sorted { FileManager.default.displayName(atPath: $0.path) < FileManager.default.displayName(atPath: $1.path) }