类型 函数 对象 CloudKitRecord 返回值 无 版本 版本 2024.3703 关键词 iCloud,同步,存储,CloudKit,CloudKitRecord,设置 另请参阅 CloudKitRecord CloudKitRecord:get() iCloud.recordCreate() iCloud.*
设置记录中特定字段的值。
CloudKitRecord:set( field, value )
字符串. 要设置值的字段名称。
表, 字符串, 或 数字. 要存储在记录中的值。此值通常作为包含所需 type 键的 表 传递,以及下面 记录值 中提到的相关键。但是,为了方便,字符串 和 数字 可以直接传递。
当作为表传递时,相关的type 值而有所不同。在每种情况下,所有"reference" 类型实例除外(请参阅下面的注释)。以下是每种表示类型的概要
| 类型 | 键 | Lua 类型 |
|---|---|---|
"string" |
字符串 |
字符串 |
"number" |
数字 |
数字 |
"data" |
数据 |
字符串 |
"location" |
latitude,longitude |
数字 |
"date" |
时间 |
数字 |
"reference" |
recordName,zoneName,zoneOwner,action |
字符串 |
"asset" |
路径 |
字符串 |
"array" |
数组 |
表 |
值类型为 "reference" 需要 recordName 键,但其他键是可选的。如果设置为唯一标识符,则此 recordName 值可用于将记录与具有相同标识符的父记录关联。此外,如果 action 键的值为 "deleteSelf",则该记录将成为父记录的子记录,并且在删除父记录时,该记录也将被删除。有关详细信息,请参阅下面的用法示例。
值类型为 "array" 需要 array 键,其值应为索引
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
}
)