{}
run-icon
main.swift
import Foundation func parseQuery(_ input: String) -> [String: String] { var result = [String: String]() let components = URLComponents(string: "?\(input)") // Přidáme "?" pro správnou interpretaci components?.queryItems?.forEach { item in result[item.name] = item.value ?? "" } return result } let input = "code=0&message=OK&transId=XXXX-XXXX-XXXX&redirect=https%3A%2F%2Fpay1.comgate.cz%2Finit%3Fid%3DXXXX-XXXX-XXXX" let map = parseQuery(input) print("Code:\n \(map["code"] ?? "")") print("Message:\n \(map["message"] ?? "")") print("TransId:\n \(map["transId"] ?? "")") print("Redirect:\n \(map["redirect"] ?? "")")
Output