URLComponents 사용법

|

URLComponents 를 설명한 그림입니다.

F2CE5C05-67A2-490A-821F-6F3023306896

다음은 코드입니다.

func learnComponents(){
  
  let urlString = "http://www.myhelloworld.com?param1=value1&param2=value2"
  
  let url = URL(string: urlString)!
  
  let myCompo = URLComponents(url: url, resolvingAgainstBaseURL: false)
  let items = myCompo?.queryItems

  items?.forEach({ (item) in
    print(item.name , String(item.value!) )
  })
  //result:
  //param1 Optional("value1")
  //param2 Optional("value2")
}

Comments