是否可以通过NSPersistentCloudKitContainer访问creationDate?

问题描述

在Cloudkit仪表板中,我可以看到记录的创建时间。

但是,当我使用我的应用程序时

import re
def word_search(documents,keyword):
    res=[]
    for i,j in enumerate(documents):
        if re.findall('\\b'+keyword+'\\b',j,flags=re.IGnorECASE):
            res.append(i)
    return res

我得到一个错误

NSSortDescriptor(key: "creationDate",ascending: false)

我怀疑我无法使用NSPersistentCloudKitContainer访问creationDate吗?

解决方法

您无法从Core Data模型访问creationDate,而是可以创建自己的creationDate字段。

如果要访问创建日期,则应使用CloudKit方法来获取记录或使用NSPersistentCloudKitContainer record(for managedObjectID: NSManagedObjectID)方法。