Sample code for 30+ languages & platforms
Swift

Transition from Zip.AppendOneFileOrDir to Zip.AddFile

Provides instructions for replacing deprecated AppendOneFileOrDir method calls with AddFile.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let zip = CkoZip()!

    // ...
    // ...
    var localFilePath: String? = "c:/someDir/example.dat"
    var saveExtraPath: Bool = false

    // ------------------------------------------------------------------------
    // The AppendOneFileOrDir method is deprecated:

    var entryObj: CkoZipEntry? = zip.appendOneFileOrDir(path: localFilePath, saveExtraPath: saveExtraPath)
    if zip.lastMethodSuccess == false {
        print("\(zip.lastErrorText!)")
        return
    }

    // ...
    // ...

    entryObj = nil

    // ------------------------------------------------------------------------
    // Do the equivalent using AddFile.

    // Instead of returning the zip entry object, we just return success/failure.
    success = zip.addFile(localPath: localFilePath, saveExtraPath: saveExtraPath)
    if success == false {
        print("\(zip.lastErrorText!)")
        return
    }

    // Do the following if you need the zip entry object for what was just appended.
    // The newly appended entry is the last one.
    let ze = CkoZipEntry()!
    var index: Int = zip.numEntries.intValue - 1
    zip.entry(at: index, entry: ze)

}