我无法在 CloudKit 中保存记录,为什么?

I cant save records in CloudKit, why?

我正在尝试 运行 一个应用程序,除了其他内容外,它还会将学校 类 加载到 table 视图中。代码如下所示:

import UIKit
import CloudKit

class AddPostVC: UIViewController {

    @IBOutlet weak var postText: UITextView!
    let database = DatabaseController()

    override func viewDidLoad() {
        super.viewDidLoad()

        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIInputViewController.dismissKeyboard))

        view.addGestureRecognizer(tap)
    }

    //Calls this function when the tap is recognized.
    func dismissKeyboard() {
        //Causes the view (or one of its embedded text fields) to resign the first responder status.
        view.endEditing(true)
    }

    @IBAction func postButtonPressed() {
        let newPost = Post()

        newPost.text = postText.text
        newPost.user = CKReference(recordID: CKRecordID(recordName: UserDefaults.standard.string(forKey: "userRecordID")!), action: CKReferenceAction.none)

        newPost.save() { _, error in
            if error == nil {
                DispatchQueue.main.async {
                    self.navigationController?.popViewController(animated: true)

                    self.dismiss(animated: true, completion: nil)
                }
            } else {
                if !self.database.networkCheck() {
                    DispatchQueue.main.async {
                        self.displayErrorMessage(message: "It seems that there is no internet connection, try again")
                    }
                } else {
                    DispatchQueue.main.async {
                        self.displayErrorMessage(message: error.debugDescription + ". Contact Apple or us for help")
                    }
                }
            }

        }

    }

    func displayErrorMessage(message:String) {

        let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert)

        let dismissAction = UIAlertAction(title: "Dismiss", style: .default, handler: nil)

        alert.addAction(dismissAction)

        self.present(alert, animated: true)

    }

}

当代码为 运行 时,它 returns 我出错了:

[LogFacilityCK] Got a connection error for operation 69CB31B15036D50D: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.cloudd" UserInfo={NSDebugDescription=connection to service named com.apple.cloudd}

有谁知道如何解决这个问题?到目前为止,我在互联网上找不到任何解决方案。

导致这个问题的一个非常重要的事情是用 cloudKit 保存了一个不同于 CKRecord 类型的记录。在我的例子中,class Post() 中的函数 save() 试图保存自己,它是 CKRecord 的子 class 而不是纯 CKRecord.

另一件阻止它工作的事情是描述和回答的事情