我有3种记录类型,它们包含这样的属性:
客户端
用户名:字符串 ProfilImage : UIImage
评论
用户:客户参考 消息:字符串
商店
评论:评论参考列表
我可以从Shop CKRecord对象中获取客户端用户名和CKRecord吗?我可以这样做:
如果有一条路,最好的办法是什么?
发布于 2016-05-19 02:50:33
下面是步骤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 {$0.record!.recordID == ref.recordID }
return matchingComments
}
let shopComments = shops.map { commentsWithReference($0.commentRef!) }https://stackoverflow.com/questions/37296223
复制相似问题