Sample code for 30+ languages & platforms
Swift Requires Chilkat v11.2.0+

Base62 Encoding and Decoding

Demonstrates base62 encoding and decoding.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    let bd = CkoBinData()!

    //  Base62 encode.
    bd.appendString(str: "hello world", charset: "utf-8")
    var base62_encoded: String? = bd.getEncoded(encoding: "base62")
    print("hello world --> \(base62_encoded!)")

    //  Output: 
    //  hello world --> AAwf93rvy4aWQVw

    //  Base62 decode
    let sb = CkoStringBuilder()!
    sb.decodeAndAppend(value: "AAwf93rvy4aWQVw", encoding: "base62", charset: "utf-8")
    print("decoded: \(sb.getAsString()!)")

    //  Output:
    //  decoded: hello world

}