Things take time

[SWIFT] URL형식으로 된 String에서 Parameter 추출 본문

iOS (기능)

[SWIFT] URL형식으로 된 String에서 Parameter 추출

겸손할 겸 2021. 11. 19. 13:21
func getQueryStringParameter(url: String, param: String) -> String? {
    guard let url = URLComponents(string: url) else {
        return nil
    }
    return url.queryItems?.first(where: { $0.name == param })?.value
}

[예시]

 

print("[Gyeom] :: \(getQueryStringParameter(url: "https://g-y-e-o-m.tistory.com/manage/newpost/?type=post&returnURL=%2Fmanage%2Fposts%2F", param: "returnURL")"