我如何从CloudKit中的CKReference列表中获取记录ID

时间:2016-06-10 17:49:20

标签: ios swift cloudkit

我有这两个案例:

1)架构的参考属性

let userReference = user!["friend"] as! CKReference
print(userReference.recordID)

2)架构上的参考列表属性

let userReferenceList = user!["friends"] as! [CKReference]
print(userReferenceList)

在第一个控制台中打印recordID,没有问题。在第二个控制台打印所有的东西,但我不能把userReferenceList.recordID

如果我编码为! CKReference而不是! [CKReference],我可以编码userReferenceList.recordID方法,但应用崩溃。

现在的问题是:

arraList

总是1。

这个2数组在类的顶部声明。

  var amicoList : [CKRecord] = [] 
  var arraList = []

代码是:

// ...

let user = records?.first
print(user!["surname"] as! String)


let userReferenceList = user!["friends"] as! [CKReference] // this is reference list on CloudKit schema

print(userReferenceList.count)
// here is ok, result is 2


for i in userReferenceList {
print(i.recordID)
let predicate = NSPredicate(format: "recordID = %@", argumentArray: [i.recordID])
let query = CKQuery(recordType: "UserProfile", predicate: predicate)
publicData.performQuery(query, inZoneWithID: nil) {
(records, error) in
if error == nil {
for record in records! {
   print(record["name"]!)
   print(record["surname"]!)

   self.amicoList = records!
   self.arraList = self.amicoList
   print(self.arraList.count)
   // here is the problem, result is 1 instead of 2

   // ...

0 个答案:

没有答案