I have a RecordType Account and another one Friends.
For Account I am setting the RecordID on creation of each record and I have a column Name.
For Friends I have two columns, Me and MyFriend. MyFriend is a Reference containing the RecordID of an Account.
How can I retrieve the Names of Accounts that are my friends?
I need to query Friends to get all the records where Me is my RecordID and then I need to use these references of the records to get the Names from the Account table.
I have tried the following but I get no results:
let predicate = NSPredicate(format: "Me = %@", recordID)
let query = CKQuery(recordType: "Friends", predicate: predicate)
publicDB.performQuery(query, inZoneWithID: nil) { (results, error) -> Void in
if error != nil {
println("Error fetching from Friends table: \(error.description)")
} else {
for friend in results {
var key = friend.objectForKey("MyFriend") as String
self.publicDB.fetchRecordWithID(CKRecordID(recordName: key), completionHandler: { (record, error) -> Void in
if error != nil {
println(error.description)
} else {
self.friends.append(record.objectForKey("Name") as String)
}
})
}
dispatch_semaphore_signal(self.semaphore)
}
}
dispatch_semaphore_wait(self.semaphore, DISPATCH_TIME_FOREVER)`