Created
February 22, 2023 15:30
-
-
Save yannxou/398397a1aa057c960f7071ba1e596a68 to your computer and use it in GitHub Desktop.
Swift: Split filename and extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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