URL解析-URLComponents

101 阅读1分钟

let components = URLComponents(url: fakeUrl, resolvingAgainstBaseURL: false)!

 

 

http://10.100.140.84/m/cashboard/cost/02?yyyyMM=2018-06&tabFlag=02

  - scheme : "http"

  - host : "10.100.140.84"

  - path : "/m/cashboard/cost/02"

  ▿ queryItems : 2 elements

    ▿ 0 : yyyyMM=2018-06

      - name : "yyyyMM"

      ▿ value : Optional

        - some : "2018-06"

    ▿ 1 : tabFlag=02

      - name : "tabFlag"

      ▿ value : Optional

        - some : "02"

 

http://10.100.140.84/m/cashboard/#/cost/02?yyyyMM=2018-06&tabFlag=02

  - scheme : "http"

  - host : "10.100.140.84"

  - path : "/m/cashboard/"

  - fragment : "/cost/02?yyyyMM=2018-06&tabFlag=02"

func getURL(scheme: String, host: String, port: Int, path: String) -> URL { 
     var components = URLComponents() 
     components.scheme = scheme 
     components.host = host 
     components.port = port 
     components.path = path 
     return components.url! 
}