Cloudkit CKRecord.Reference returns nil

Hey all,

Any Cloudkit experts?

I have a routine that keeps returning nil and I need a kick in the right direction.

The following code is returning nil and I am not sure why. Any help will be greatly appreciated.

Cloudkit Dashboard has a custom type Items and the following custom fields:

list: Reference, Queryable
name: String, Queryable, Searchable, Sortable
number: Int(64), Queryable, Sortable

 let privateDatabase = CKContainer.default().privateCloudDatabase

        if item == nil {
            //create a record
            item = CKRecord(recordType: "Items")

         //Check for  nil
         print ("Record is \(String(describing: list?.recordID))")

        guard (list?.recordID) != nil else {
            dismiss(animated: true, completion: nil)
            return }

         let listReference = CKRecord.Reference(recordID: list.recordID, action: .deleteSelf)

         item?.setObject(listReference, forKey: "list")

    }

Thanks for any pointer you can send my way

Blessings,
—Mark

Ok lesson learned!

I simply forgot to add a segue Identifier. Doh.

I wish these encode error were a bit more verbose!! :slight_smile:
Blessings,
—Mark

1 Like