CloudKitRecord:get()

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

Overview

Retreives the value of a specific field in a record. Because Lua data types do not directly match CloudKit data types, CloudKit record values are packaged and returned as a table. This table will contain specific properties depending on the record value's type — see Record Values below for details.

Syntax

CloudKitRecord:get( field )
field (required)

String. The field name to retreive the value from.

Record Values

The returned table has a type property and its contents vary depending on this property value. Here is the outline for each represented type:

Type Properties Lua Type
"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

Examples

String
local function fetchResults( event )

    if event.record then
        local value = event.record:get( "meeting" )
        if ( value and value.type == "string" ) then
            print( "Meeting:", value.string )
        end
    end
end

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

    if event.record then
        local value = event.record:get( "when" )
        if ( value and value.type == "date" ) then
            print( "When:", value.time )
        end
    end
end

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

    if event.record then
        local value = event.record:get( "where" )
        if ( value and value.type == "location" ) then
            print( "Where:", value.latitude .. ", " .. value.longitude )
        end
    end
end

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