Skip to content

Instantly share code, notes, and snippets.

@yannxou
Created February 22, 2023 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannxou/398397a1aa057c960f7071ba1e596a68 to your computer and use it in GitHub Desktop.
Save yannxou/398397a1aa057c960f7071ba1e596a68 to your computer and use it in GitHub Desktop.
Swift: Split filename and extension
private func fileComponents(_ fileName: String) -> (name: String, extension: String) {
let fileExtension = URL(fileURLWithPath: fileName).pathExtension
let fileNameOnly = fileExtension.isEmpty ? fileName : String(fileName.dropLast(fileExtension.count + 1))
return (fileNameOnly, fileExtension)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment