Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Created April 23, 2018 10:37
Show Gist options
  • Save KentarouKanno/d0e9cc67610fe3ea2a3ffb506cb9bac6 to your computer and use it in GitHub Desktop.
Save KentarouKanno/d0e9cc67610fe3ea2a3ffb506cb9bac6 to your computer and use it in GitHub Desktop.
URL

URL

var url = URL(string: "http://user:password@www.example.com:8080/hoge/fuga/index.html?a=1&b=2#test")

print("absoluteString :", url?.absoluteString ?? "")
/* absoluteString : http://user:password@www.example.com:8080/hoge/fuga/index.html?a=1&b=2#test */

print("absoluteURL :", url?.absoluteURL ?? "")
/* absoluteURL : http://user:password@www.example.com:8080/hoge/fuga/index.html?a=1&b=2#test */

print("baseURL :", url?.baseURL ?? "")
/* baseURL : */

print("fragment :", url?.fragment ?? "")
/* fragment : test */

print("host :", url?.host ?? "")
/* host : www.example.com */

print("lastPathComponent :", url?.lastPathComponent ?? "")
/* lastPathComponent : index.html */

print("password :", url?.password ?? "")
/* password : password */

print("path :", url?.path ?? "")
/* path : /hoge/fuga/index.html */

print("pathComponents :", url?.pathComponents ?? "")
/* pathComponents : ["/", "hoge", "fuga", "index.html"] */

print("pathExtension :", url?.pathExtension ?? "")
/* pathExtension : html */

print("port :", url?.port ?? "")
/* port : 8080 */

print("query :", url?.query ?? "")
/* query : a=1&b=2 */

print("relativePath :", url?.relativePath ?? "")
/* relativePath : /hoge/fuga/index.html */

print("relativeString :", url?.relativeString ?? "")
/* relativeString : http://user:password@www.example.com:8080/hoge/fuga/index.html?a=1&b=2#test */

print("scheme :", url?.scheme ?? "")
/* scheme : http */

print("user :", url?.user ?? "")
/* user : user */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment