PHCollectionListChangeRequest
PHCollectionListChangeRequest
PHCollectionListChangeRequest Class of Photos A request to create, delete, or modify a Photos collection list, for use in a photo library change block.
class PHCollectionListChangeRequestOverview
You use the PHCollectionListChangeRequest class to request changes for PHCollectionList objects. To make changes to collection lists (such as folders containing user-created albums) in the Photos library, create a change request using the appropriate class method for the change you want to perform.
- Call the creationRequestForCollectionList(withTitle:)) method to create a new asset collection.
- Call the deleteCollectionLists(:)) method to delete existing asset collections.
- Call the init(for:)) or init(for:childCollections:)) method to modify a collection’s metadata or its list of child collections.
Before creating a change request, use the canPerform(:)) method to verify that the collection allows the edit operation you’re requesting. If you attempt to perform an unsupported edit operation, Photos throws an exception.
A change request for creating or modifying a collection list works like a mutable version of the collection list object. Use the change request’s properties and instance methods to request changes to the collection list itself. For example, the following code removes an album from a folder.
Swift:
PHPhotoLibrary.shared().performChanges {
let request = PHCollectionListChangeRequest(for: folder,
childCollections: folderContentsFetchResult)
request!.removeChildCollections([album!] as NSFastEnumeration)
} completionHandler: { success, error in
print("Finished removing the album from the folder. \(success ? "Success" : String(describing: error))")
}Objective-C:
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHCollectionListChangeRequest *request =
[PHCollectionListChangeRequest changeRequestForCollectionList:folder
childCollections:folderContentsFetchResult];
[request removeChildCollections:@[ album ]];
} completionHandler:^(BOOL success, NSError *error) {
NSLog(@"Finished removing the album from the folder. %@", (success ? @"Success" : error));
}];After Photos runs the change block and calls your completion handler, the collection list’s state reflects the changes you requested in the block.
If you create or use a change request object outside a photo library change block, Photos raises an Objective-C exception. For details on change blocks, see PHPhotoLibrary.
Inherits From
Conforms To
CVarArg CustomDebugStringConvertible CustomStringConvertible Equatable Hashable NSObjectProtocol