Sample code for 30+ languages & platforms
Swift

URL Encoding and Decoding

Demonstrates URL encoding/decoding using the HTTP convenience methods.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    let http = CkoHttp()!

    var s: String? = "Hello World! 100% sure."

    var encoded: String? = http.urlEncode(str: s)
    print("URL encoded: \(encoded!)")

    // Space → %20
    // ! → %21
    // % → %25

    var decoded: String? = http.urlDecode(str: encoded)
    print("URL decoded: \(decoded!)")

    // Output:

    // URL encoded: Hello%20World%21%20100%25%20sure.
    // URL decoded: Hello World! 100% sure.

}