karwa/swift-url

Add a way to modify file extensions

karwa opened this issue · 0 comments

karwa commented

e.g. changing myfile.jpg to myfile.zip. Particularly useful for "file" URLs.

Possibly implement with an extension on String? Extensions can be useful anywhere inside a path, for example:

let url = WebURL("file:///Applications/MyApp.app/Contents/Resources/foo")!

if let appBundleDirIdx = url.pathComponents.lastIndex(where: { $0.fileExtension == "app" }) {
  let pathInsideBundleIdx = url.pathComponents.index(after: appBundleDirIdx)
  let pathInsideBundle = url.pathComponents[pathInsideBundleIdx...] // "/Contents/Resources/foo"
}