CloudKitRecord:set()

类型 函数
对象 CloudKitRecord
返回值
版本 版本 2024.3703
关键词 iCloud,同步,存储,CloudKit,CloudKitRecord,设置
另请参阅 CloudKitRecord
CloudKitRecord:get()
iCloud.recordCreate()
iCloud.*

概述

设置记录中特定字段的值。

语法

CloudKitRecord:set( field, value )
字段(必填)

字符串. 要设置值的字段名称。

(必填)

字符串数字. 要存储在记录中的值。此值通常作为包含所需 type 键的 传递,以及下面 记录值 中提到的相关键。但是,为了方便,字符串数字 可以直接传递。

记录值

当作为表传递时,相关的键值对根据其 type 值而有所不同。在每种情况下,所有键值对都是必需的,"reference" 类型实例除外(请参阅下面的注释)。以下是每种表示类型的概要

类型 Lua 类型
"string" 字符串 字符串
"number" 数字 数字
"data" 数据 字符串
"location" latitudelongitude 数字
"date" 时间 数字
"reference" recordNamezoneNamezoneOwneraction 字符串
"asset" 路径 字符串
"array" 数组
注释
  • 值类型为 "reference" 需要 recordName 键,但其他键是可选的。如果设置为唯一标识符,则此 recordName 值可用于将记录与具有相同标识符的父记录关联。此外,如果 action 键的值为 "deleteSelf",则该记录将成为父记录的子记录,并且在删除父记录时,该记录也将被删除。有关详细信息,请参阅下面的用法示例。

  • 值类型为 "array" 需要 array 键,其值应为索引(非数组)Lua 表,其中包含命名的键值键值对。

示例

标准值
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
    }
)