Creating a CKShare crashes on iOS 10 Beta 1

Originator:tom
Number:rdar://27132908 Date Originated:7/1/16
Status:Open Resolved:
Product:CloudKit Product Version:iOS 10 Beta Build 1
Classification:Bug Reproducible:Every time
 
Summary:
I'm trying to create a CKShare from a CKRecord. However, I always get this error:
 
2016-07-01 06:51:12.945321 myApp[7695:874420] *** Assertion failure in -[CKRecord setShare:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CloudKit/CloudKit-615.8/Framework/CKRecord.m:923
2016-07-01 06:51:12.945742 mypp[7695:874420] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Share must be in the same zone as the current record'
 
I share them in the same CKModifyRecordsOperation though, so I can't imagine why the original winds up in one zone, while the share winds up in another. If I remove the shareRecord from the RecordsOperation, it saves just fine. I've even tried to create the original in one RecordsOperation, then create the share in another RecordsOperation, but still get the same error.
 
Note: I just checked in the CloudKit Dashboard. The share property of the runRecord does get populated and a cloudkit.share recordType does get created in my private zone, but whenever I try to browse the cloudkit.share recordType to see the record, it fails and asks me to send Apple a report.
 
Here's the source to the code:
                let myAppCKContainer:CKContainer = CKContainer.init(identifier: "iCloud.com.omegaortega.myApp")
                let myAppCKDatabase:CKDatabase = myAppCKContainer.privateCloudDatabase;
 
                let recordZoneID = CKRecordZoneID.init(zoneName: "myAppData", ownerName:self.curUserId! )
                let recordString:String = "\(Date.timeIntervalSinceReferenceDate)-\(run.name)"
                let myAppRecordID:CKRecordID = CKRecordID.init(recordName: recordString, zoneID: recordZoneID)
                let myAppRecord:CKRecord = CKRecord.init(recordType: "Run", recordID: myAppRecordID)
                let runRef:CKReference = CKReference.init(record: myAppRecord, action: CKReferenceAction.none)
                let stopRecordString:String = "\(Date.timeIntervalSinceReferenceDate)-\(run.name)"
                let stopRecordID:CKRecordID = CKRecordID.init(recordName: stopRecordString, zoneID: recordZoneID)
                let stopRecord:CKRecord = CKRecord.init(recordType: "Stop", recordID: stopRecordID)
                stopRecord["run"] = runRef
                stopRecord["name"] = stop.name
                if let location:CLLocation = stop.location {
                    stopRecord["location"] = location
                }
 
                let shareRecord = CKShare(rootRecord: myAppRecord)
 
 
                let recordOp = CKModifyRecordsOperation.init(recordsToSave: [stopRecord,myAppRecord,shareRecord], recordIDsToDelete: nil)
                recordOp.modifyRecordsCompletionBlock =  { (records:[CKRecord]?, recordIDs:[CKRecordID]?, error:NSError?) in
                    print("saved")
                    if let allRecords = records {
                        for record:CKRecord in allRecords {
                            switch record.recordType {
                            case "Run":
                                self.runRecord = record
                                break
                            case "Stop":
                                self.stopRecord = record
                                break
                 
                            default:
                                break
                            }
                        }
                    }
     
     
                }
                myAppCKDatabase.add(recordOp);

Steps to Reproduce:
1. create a record
2. create a share with that record
3. save both in a modifyRecords op
4. App crashes

Expected Results:
Expect the CKRecord not to crash when setting the share

Actual Results:
2016-07-01 06:51:12.945321 myApp[7695:874420] *** Assertion failure in -[CKRecord setShare:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CloudKit/CloudKit-615.8/Framework/CKRecord.m:923
2016-07-01 06:51:12.945742 mypp[7695:874420] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Share must be in the same zone as the current record'

Version:
iOS 10 Beta Build 1

Notes:
I modified my code to use the UICloudSharingController and still experienced the same thing.

Configuration:
iPhone 6S+

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!