2

I have an application where I need to keep an index over files in a directory and I need to be able to access these files. However, when I have a URL object and call the absoluteString to get the path to either folder or a file it prepends the String with file://. First of I am not sure why it does this and secondly, how to avoid this, without utilising string manipulation.

/Lars

Lars Nielsen
  • 1,468
  • 16
  • 29

1 Answers1

5

You can use path: String? property of your URL instance

if url.isFileURL, let path = url.path {
    print(path)
} else {
    print("Not file URL")    
}
Modo Ltunzher
  • 600
  • 4
  • 10