UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

'modifyRecordZonesCompletionBlock' was deprecated in iOS 15.0: Use modifyRecordZonesResultBlock instead

Forums > SwiftUI

I've been using the CloudKitHelper Class that I found here. My app is only on iOS16, so getting the above message is something I'd like to remove. I've looked everywhere and have not found any examples of people dealing with the new method. Given that the CloudKitHelper class is using recursion a simple replacement of operaion.modifyRecordZonesCompletionBlock to operation.modifyRecordZonesResultBlock, provides many more errors.

    public static func modifyRecordZonesOperation(
        database: CKDatabase,
        recordZonesToSave: [CKRecordZone]?,
        recordZoneIDsToDelete: [CKRecordZone.ID]?,
        modifyRecordZonesCompletionBlock: @escaping (([CKRecordZone]?, [CKRecordZone.ID]?, Error?) -> Void)) {
            let logger=Logger(subsystem: "tracker", category: "PersistentCloudKitContainer")
            let operation = CKModifyRecordZonesOperation(
                recordZonesToSave: recordZonesToSave,
                recordZoneIDsToDelete: recordZoneIDsToDelete)
            // swiftlint:disable:next line_length
            operation.modifyRecordZonesCompletionBlock = { (savedRecordZones: [CKRecordZone]?, deletedRecordZoneIDs: [CKRecordZone.ID]?, error: Error?) -> Void in
                if let error = error {
                    if let delay = determineRetry(error: error) {
                        DispatchQueue.global().asyncAfter(deadline: .now() + delay) {
                            CloudKitHelper.modifyRecordZonesOperation(
                                database: database,
                                recordZonesToSave: recordZonesToSave,
                                recordZoneIDsToDelete: recordZoneIDsToDelete,
                                modifyRecordZonesCompletionBlock: modifyRecordZonesCompletionBlock)
                        }
                        logger.log("modifyRecord Error \(error.localizedDescription), trying delayed retry of \(delay)")
                    } else {
                        modifyRecordZonesCompletionBlock(savedRecordZones, deletedRecordZoneIDs, error)
                    }
                } else {
                    modifyRecordZonesCompletionBlock(savedRecordZones, deletedRecordZoneIDs, error)
                }
            }
            database.add(operation)
        }

I would appreciate any pointers at how to address this. Thanks

1      

Is it an error such that it will not compile, or merely a warning?

Generally, "deprecated" means you can still use it, but Apple encourages you to transition away from it because it will be discontinued eventually, possibly years from now.

1      

It is currently a warning, but I'd like to see how to do it correctly going forward. I tried just chaning .modifyRecordZonesCompletionBlock to .modifyRecordZonesResultBlock but the signature is very different. It seems like it will break the recursion approach used by the above code.

1      

Looking at Apple Documents modifyRecordZonesResultBlock while it not very helpful, it say that it use Result type not completion handlers. So it writing the hander return .success or .failure. I am not sure.

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.