首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >正在终止应用程序,原因:“”containerIdentifier不能为nil“”正在使用类型CKException的未捕获异常终止

正在终止应用程序,原因:“”containerIdentifier不能为nil“”正在使用类型CKException的未捕获异常终止
EN

Stack Overflow用户
提问于 2021-08-16 19:37:16
回答 1查看 76关注 0票数 0

我是Swift的新手。我和CloudKit有了我的第一个项目。但不幸的是,我在从CloudKit获取数据时遇到错误:

我得到这个错误:

代码语言:javascript
运行
复制
*** Terminating app due to uncaught exception 'CKException', reason: 'containerIdentifier can not be nil'
terminating with uncaught exception of type CKException

使用以下代码:

代码语言:javascript
运行
复制
import Foundation
import CloudKit

class CKRelation {
    static let database = CKContainer.default().publicCloudDatabase

    class func fetch(completion: @escaping (Result<[Relation], Error>) -> ()) {
        let predicate = NSPredicate(value: true)
        let name = NSSortDescriptor(key: "LastName", ascending: true)
        let query = CKQuery(recordType: "Clients", predicate: predicate)
        query.sortDescriptors = [name]

        let operation = CKQueryOperation(query: query)
        operation.desiredKeys = ["FirstName", "Initials", "LastName", "MiddleName", "RelationId"]
        operation.resultsLimit = 50

        var newRelations = [Relation]()

        operation.recordFetchedBlock = { record in
            var relation = Relation()
            relation.recordID = record.recordID
            relation.FirstName = record["FirstName"] as! String
            relation.Initials = record["Initials"] as! String
            relation.LastName = record["LastName"] as! String
            relation.MiddleName = record["MiddleName"] as! String
            relation.RelationId = record["RelationId"] as! Int
            
            newRelations.append(relation)
        }

        operation.queryCompletionBlock = { (cursor, error) in
            DispatchQueue.main.async {
                if let error = error {
                    completion(.failure(error))
                } else {
                    completion(.success(newRelations))
                    print("data")
                }
            }
        }
        database.add(operation)
    }

我在网上找不到任何东西。希望有人能帮我。

EN

Stack Overflow用户

发布于 2021-08-17 21:01:40

因为我忘了一些事情这里是一些更多的信息:

代码位于第12行:‘static let database =CKContainer.default()..publicCloudDatabase’

不幸的是,我没有更进一步。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68808373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档