I'm working on a macOS Swift-app where I need to perform folder/file traversal. In this specific instance, I need to remove the first part of a file path...i.e., if a file has the path of MyFolder/MyItem, I need it to just read as MyItem for display purposes.
Based off the responses in this answer, I wrote the following code:
if fileString.hasPrefix("/") {
fileString.remove(at: fileString.startIndex)
print(fileString)
}
...where I remove any part of the fileString before and including "/".
However, this doesn't seem to work in practice....MyFile/MyItem doesn't get changed to MyItem, it remains as MyFile/MyItem.