CloudKitRecord:get()

类型 函数
对象 CloudKitRecord
返回值
修订 版本 2024.3703
关键词 iCloud,同步,存储,CloudKit,CloudKitRecord,获取
另请参阅 CloudKitRecord
CloudKitRecord:set()
CloudKitRecord:table()
iCloud.*

概述

检索记录中特定字段的值。由于 Lua 数据类型与 CloudKit 数据类型不直接匹配,CloudKit 记录值被打包并作为 返回。此表将包含特定属性,具体取决于记录值的类型 — 有关详细信息,请参阅下面的 记录值

语法

CloudKitRecord:get( field )
字段 (必填)

字符串 要检索其值的字段名称。

记录值

返回的表具有 type 属性,其内容根据此属性值而变化。以下是每种表示类型的概要

类型 属性 Lua 类型
"string" 字符串 字符串
"number" 数字 数字
"data" 数据 字符串
"location" latitudelongitude 数字
"date" 时间 数字
"reference" recordNamezoneNamezoneOwneraction 字符串
"asset" 路径 字符串
"array" 数组

示例

字符串
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
    }
)
日期
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
    }
)
位置
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
    }
)