Skip to content

Instantly share code, notes, and snippets.

@nubbel
Last active August 25, 2016 09:21
Show Gist options
  • Save nubbel/aba4e6ac785c8606caad to your computer and use it in GitHub Desktop.
Save nubbel/aba4e6ac785c8606caad to your computer and use it in GitHub Desktop.
import Foundation
extension NSURL : StringLiteralConvertible {
class func convertFromStringLiteral(value: String) -> Self {
return self(string: value)
}
class func convertFromExtendedGraphemeClusterLiteral(value: String) -> Self {
return self(string: value)
}
}
var url: NSURL = "http://google.com"
url.host // => google.com
url.scheme // => http
func hostFromURL(URL: NSURL) -> String {
return URL.host
}
// String literal is automatically converted to NSURL
hostFromURL("http://google.com") // => google.com
// wow, even that works
"http://google.com".host // => google.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment