var url = NSURL(string: "http://www.baidu.com/index/main.css?username=zhangsan&age=20#id/123/tag/man")
println("scheme: \(url?.scheme)")
println("host: \(url?.host)")
println("port: \(url?.port)")
println("path: : \(url?.path)")
println("query: \(url?.query)")
println("relativePath: \(url?.relativePath)")
println("pathComponents: \(url?.pathComponents)")
println("parameterString: \(url?.parameterString)")
println("query: \(url?.query)")
println("fragment: \(url?.fragment)")
println("user: \(url?.user)")
println("password: \(url?.password)")
结果如下:
scheme: Optional("http")
host: Optional("www.baidu.com")
port: nil
path: : Optional("/static/main.css")
query: Optional("username=zhangsan&age=20")
relativePath: Optional("/static/main.css")
pathComponents: Optional([/, static, main.css])
parameterString: nil
query: Optional("username=zhangsan&age=20")
fragment: Optional("id/123/tag/man")
user: nil
password: nil