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

Transition from Zip.AppendBd to Zip.AddBd

Provides instructions for replacing deprecated AppendBd method calls with AddBd.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let zip = CkoZip()!

    //  ...
    //  ...

    var pathInZip: String? = "example.dat"

    let bd = CkoBinData()!
    bd.loadFile(path: "c:/someDir/example.dat")

    //  ------------------------------------------------------------------------
    //  The AppendBd method is deprecated:
    //  AppendBd returns the zip entry object, which is usually not needed.

    var entryObj: CkoZipEntry? = zip.appendBd(pathInZip: pathInZip, byteData: bd)
    if zip.lastMethodSuccess == false {
        print("\(zip.lastErrorText!)")
        return
    }

    //  ...
    //  ...

    entryObj = nil

    //  ------------------------------------------------------------------------
    //  Do the equivalent using AddBd.

    //  Instead of returning the zip entry object, we just return success/failure.
    success = zip.addBd(pathInZip: pathInZip, bd: bd)
    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)

}