Sample code for 30+ languages & platforms
Swift

Get Contents of File as Base64

See more Encryption Examples

Demonstrates how to read the contents of a file and convert to a base64 string.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let bd = CkoBinData()!

    success = bd.loadFile(path: "qa_data/jpg/starfish.jpg")
    if success == false {
        print("Failed to load file.")
        return
    }

    print("\(bd.getEncoded(encoding: "base64")!)")

    // If you want mult-line base64:
    print("--")
    print("\(bd.getEncoded(encoding: "base64_mime")!)")

    // If you want hex..
    print("--")
    print("\(bd.getEncoded(encoding: "hex")!)")

    // etc.

}