Sample code for 30+ languages & platforms
Swift

XMP Array Property - Bag, Seq, or Alt

See more XMP Examples

How to insert or update an XMP array property (bag, seq, or alt).

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

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

    let xmp = CkoXmp()!

    // Load a JPG or TIF image file.
    // Sample JPG's with XMP metadata may be found at:
    // http://www.chilkatsoft.com/testData/xmp/sample1.jpg
    // http://www.chilkatsoft.com/testData/xmp/sample2.jpg
    // http://www.chilkatsoft.com/testData/xmp/sample3.jpg
    success = xmp.loadAppFile(path: "sample1.jpg")
    if success != true {
        print("\(xmp.lastErrorText!)")
        return
    }

    print("Num embedded XMP docs: \(xmp.numEmbedded.intValue)")

    // Assuming there is at least one, get the 1st.
    // (There is typically never more than one, but theoretically it's possible.)
    var xml: CkoXml?
    xml = xmp.getEmbedded(index: 0)
    if xmp.lastMethodSuccess == true {

        // Create an object to hold one or more string values.
        let sa = CkoStringArray()!
        success = sa.append(str: "value_1")
        success = sa.append(str: "value_2")
        // ...

        success = xmp.addArray(xml: xml, arrType: "bag", propName: "Iptc4xmpCore:Chilkat", values: sa)
        if success != true {
            print("\(xmp.lastErrorText!)")
        }
        else {
            // Save the JPG.
            success = xmp.saveAppFile(path: "modified.jpg")
            if success != true {
                print("\(xmp.lastErrorText!)")
            }

        }

        xml = nil

    }
    else {
        print("\(xmp.lastErrorText!)")
    }


}