从 CKReference 中获取一个 CKReference 对象
Fetch a CKReference object from a CKReference
我有 3 种记录类型,其中包含如下属性:
客户
Username : String
ProfilImage : UIImage
评论
User : Client Reference
Message : String
商店
Comments : Comment Reference List
我可以从 Shop CKRecord 对象中获取客户端用户名和 ProfilImage 吗?我可以这样做吗:
- 从店铺记录中获取评论引用
- 从找到的每个评论引用中获取用户引用
- 最后从店铺记录的评论参考的用户参考中获取用户名和个人资料
如果有路径,最好的方法是什么?
这是第 1 步的示例。其他步骤将与您列出的步骤类似,并在每个先前步骤的结果上级联。 (注意:不需要明确的 CKReference 字段,因为它们可以从 CKRecord 变量中收集到,但我想让示例更具可读性)
struct Shop {
// other variables....
var record : CKRecord?
var commentRef : CKReference?
}
struct Comment {
// other variables....
var record : CKRecord?
var clientRef : CKReference?
}
var shops : [Shop]
var comments : [Comment]
func commentsWithReference(ref: CKReference) -> [Comment] {
let matchingComments = comments.filter {[=10=].record!.recordID == ref.recordID }
return matchingComments
}
let shopComments = shops.map { commentsWithReference([=10=].commentRef!) }
我有 3 种记录类型,其中包含如下属性:
客户
Username : String
ProfilImage : UIImage
评论
User : Client Reference
Message : String
商店
Comments : Comment Reference List
我可以从 Shop CKRecord 对象中获取客户端用户名和 ProfilImage 吗?我可以这样做吗:
- 从店铺记录中获取评论引用
- 从找到的每个评论引用中获取用户引用
- 最后从店铺记录的评论参考的用户参考中获取用户名和个人资料
如果有路径,最好的方法是什么?
这是第 1 步的示例。其他步骤将与您列出的步骤类似,并在每个先前步骤的结果上级联。 (注意:不需要明确的 CKReference 字段,因为它们可以从 CKRecord 变量中收集到,但我想让示例更具可读性)
struct Shop {
// other variables....
var record : CKRecord?
var commentRef : CKReference?
}
struct Comment {
// other variables....
var record : CKRecord?
var clientRef : CKReference?
}
var shops : [Shop]
var comments : [Comment]
func commentsWithReference(ref: CKReference) -> [Comment] {
let matchingComments = comments.filter {[=10=].record!.recordID == ref.recordID }
return matchingComments
}
let shopComments = shops.map { commentsWithReference([=10=].commentRef!) }