CloudKit - Saving record progress doesn't perform as expected

146 Views Asked by At

I've a function that saves a record with an image to CloudKit.

Everything works as expected and the records are saved and fetched without issues.

I want to display the upload progress for better UX but when I'm printing the progress in my operation.perRecordProgressBlock {} the output comes like

0.0 0.097003 0.990101 1.0

So the progress goes from 0.1% to 99% straight.

I expected something like 10%, 20% and so on...

The save record code used is the following:

func savePost(_ xrecord: CKRecord) {
    let publicData = CKContainer.default().publicCloudDatabase
    let record: [CKRecord] = [xrecord] // array with a single object
    let saveOperation = CKModifyRecordsOperation.init(recordsToSave: record, recordIDsToDelete: nil)

    saveOperation.perRecordProgressBlock = {(_, progress) -> Void in
        print("\(Float(progress))") 
    }
    saveOperation.perRecordCompletionBlock = {(record, error) -> Void in
        print("completed...")
    }
    publicData.add(saveOperation)
}

Is that any way to keep the progress "smooth"? Like using a completionHandler somehow?

Tips are welcome.

Thanks :D

0

There are 0 best solutions below