URLComponents 사용법
20 Oct 2018 | swiftURLComponents 를 설명한 그림입니다.
다음은 코드입니다.
func learnComponents(){
let urlString = "http://www.myhelloworld.com?param1=value1¶m2=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