CloudKitRecord:set()

Type Function
Object CloudKitRecord
Return value none
Revision Release 2024.3703
Keywords iCloud, sync, storage, CloudKit, CloudKitRecord, set
See also CloudKitRecord
CloudKitRecord:get()
iCloud.recordCreate()
iCloud.*

Overview

Sets the value of a specific field in a record.

Syntax

CloudKitRecord:set( field, value )
field (required)

String. The field name for which to set the value.

value (required)

Table, String, or Number. Value to store in the record. This value is typically passed as a table containing the required type key, along with the associated keys noted in Record Values below. However, strings and numbers can be passed directly as a convenience method.

Record Values

When passed as a table, the associated key-value pairs vary depending on its type value. In each case, all key-value pairs are required, except in the "reference" type instance (see notes below). Here is the outline for each represented type:

Type Keys Lua Type(s)
"string" string string
"number" number number
"data" data string
"location" latitude, longitude numbers
"date" time number
"reference" recordName, zoneName, zoneOwner, action strings
"asset" path string
"array" array table
Notes
  • Value types of "reference" require the recordName key, but the other keys are optional. If set to a unique identifier, this recordName value can be used to relate the record to a parent record with the same identifier. In addition, if the action key's value is "deleteSelf", the record becomes a child of the parent and it will be deleted if/when the parent record is deleted. See the usage example below for details.

  • Value types of "array" require the array key and its value should be an indexed (non-array) Lua table with named key-value pairs.

Examples

Standard Values
local function fetchResults( event )

    if event.record then
        -- String and number values can be passed directly (convenience method)
        event.record:set( "company", "Corona Labs" )
        event.record:set( "amount", 1 )
        -- Other value types must be passed as a table
        event.record:set( "where", { type="location", latitude=37.453139, longitude=122.113451 } )
    else
        print( "Record not fetched!" )
    end
end

iCloud.recordFetch(
    {
        recordName = "Corona Labs 1",
        onComplete = fetchResults
    }
)