Sample code for 30+ languages & platforms
Swift

Create Password Protected Zip containing a Single File.

See more Zip Examples

Create a password-protected .zip containing a single file. (This uses the older Zip 2.0 encryption scheme, which is weaker and not as secure as AES encryption, which Chilkat Zip also supports.)

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let zip = CkoZip()!

    success = zip.newZip(zipPath: "test.zip")
    if success == false {
        print("\(zip.lastErrorText!)")
        return
    }

    zip.setPassword(password: "secret")
    zip.passwordProtect = true

    var saveExtraPath: Bool
    saveExtraPath = false
    success = zip.addFile(localPath: "/temp/hamlet.xml", saveExtraPath: saveExtraPath)

    success = zip.writeAndClose()
    if success == false {
        print("\(zip.lastErrorText!)")
        return
    }

    print("Zip Created!")

}