performChanges(_:completionHandler:)
performChanges(_:completionHandler:)
performChanges(_:completionHandler:) Instance Method of PHPhotoLibrary Asynchronously runs a block that requests changes to the photo library.
func performChanges(_ changeBlock: @escaping () -> Void, completionHandler: (@Sendable (Bool, (any Error)?) -> Void)? = nil)Parameters
changeBlock
A block that requests changes to perform.
This block takes no parameters and has no return value.
completionHandler
A block that Photos calls after the change block completes and Photos performs the requested changes.
The block takes the following parameters: - term success: true if Photos successfully applied the changes requested in the block; otherwise, false. - term error: If an error occurs, an NSError object describing the error; otherwise, nil.
Discussion
Photos executes both the change block and the completion handler block on an arbitrary serial queue. To update your app’s UI as a result of a change, dispatch that work to the main queue.
Note: For each call to this method, iOS shows an alert asking the user for permission to edit the contents of the photo library. If your app needs to submit several changes at once, combine them into a single change block. For example, to edit the content of multiple existing photos, create multiple `
doc://com.apple.photokit/documentation/Photos/PHAssetChangeRequestobjects and set thedoc://com.apple.photokit/documentation/Photos/PHAssetChangeRequest/contentEditingOutputproperty on each to an independentdoc://com.apple.photokit/documentation/Photos/PHContentEditingOutput` object.