Sample code for 30+ languages & platforms
Swift

Clear All Multipart Parts

See more REST Examples

Demonstrates Rest.ClearAllParts, which removes all multipart subparts from the request under construction.

Background. Clearing the parts is useful when reusing the same Rest object to build a different multipart request.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let rest = CkoRest()!
    var bTls: Bool = true
    var bAutoReconnect: Bool = true
    success = rest.connect(hostname: "example.com", port: 443, tls: bTls, autoReconnect: bAutoReconnect)
    if success == false {
        print("\(rest.lastErrorText!)")
        return
    }

    //  Build a part.
    rest.partSelector = "1"
    success = rest.setMultipartBodyString(bodyText: "value1")
    if success == false {
        print("\(rest.lastErrorText!)")
        return
    }

    //  Remove all multipart subparts from the request under construction, for example before reusing the
    //  same Rest object for a different multipart request.
    rest.clearAllParts()

    print("All multipart parts cleared.")

}