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

HTML Encoding

Demonstrates HTML encoding and decoding.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    let crypt = CkoCrypt2()!

    var s: String? = "< é ü ç Ω Hello & World ✓ >"

    var htmlEncoded: String? = crypt.encodeString(inStr: s, charset: "utf-8", encoding: "html")
    print("\(htmlEncoded!)")

    //  Output:
    //  < &eacute; &uuml; &ccedil; &ohm; Hello & World &check; >

    //  To decode:
    s = crypt.decodeString(inStr: htmlEncoded, charset: "utf-8", encoding: "html")
    print("\(s!)")

    //  Output:
    //  < é ü ç Ω Hello & World ✓ >

}