I have 3 records types which contained attributes like this :
Username : String
ProfilImage : UIImage
User : Client Reference
Message : String
Comments : Comment Reference List
Can I fetch the client Username and ProfilImage from a Shop CKRecord object ? Can I do this path :
If there's a path, what's the best way to do this ?
Here is example for Step 1. The other steps would follow similarly from the steps you've listed, cascading on the results of each previous step. (NOTE: There is no need for the explicit CKReference fields since they can be gleaned from the CKRecord variables, but I wanted to make the example more readable)
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!) }