Skip to content

Instantly share code, notes, and snippets.

@khanlou
Created July 13, 2017 18:17
Show Gist options
  • Select an option

  • Save khanlou/288900646121497bf2c965b91bb4890f to your computer and use it in GitHub Desktop.

Select an option

Save khanlou/288900646121497bf2c965b91bb4890f to your computer and use it in GitHub Desktop.
Mutable pathExtension on URLComponents
// Swift 3
extension URLComponents {
var pathExtension: String {
get {
return NSString(string: self.path).pathExtension
}
set {
let nsStringPath = NSString(string: self.path)
let nsStringPathWithoutExtension = NSString(string: nsStringPath.deletingPathExtension)
if let nsStringWithNewExtension = nsStringPathWithoutExtension.appendingPathExtension(newValue) {
self.path = nsStringWithNewExtension
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment