0

I have an array, photoAsset, and I am trying to delete each item listed in the array from an asset collection. How do I go about doing this?

This is what I have tried

    PHPhotoLibrary.sharedPhotoLibrary().performChanges({ () -> Void in

        let request = PHAssetCollectionChangeRequest(forAssetCollection: self.assetCollection)

        //This is the number of items in my array
        println(self.photosAsset.count)

        //Only removes the FIRST item, need to remove ALL items
        request.removeAssets([self.photosAsset[0]])


        }, completionHandler: nil)
3
  • Why? The request array is defined in the scope of the block and will be released after its finished. Why remove them all? Commented Jul 12, 2015 at 23:13
  • For the function of my app, the button is to remove all photos in the library. I could go into detail of the functionality of my app but that would be pointless. I figured out the answer and posted it if you are curious. Commented Jul 12, 2015 at 23:16
  • What is in your self.photoAsset array? Are the elements PHAsset objects or arrays of PHAsset objects? Commented Jul 12, 2015 at 23:22

2 Answers 2

2

Why not request.removeAssets(self.photosAsset) rather than removing them one by one in a loop?

Sign up to request clarification or add additional context in comments.

Comments

0

I feel like an idiot, completely forgot about a for loop smh... Here is the answer.

        let request = PHAssetCollectionChangeRequest(forAssetCollection: self.assetCollection)

        self.photosAsset.count
        for (var i=0; i<self.photosAsset.count; i++) {
        request.removeAssets([self.photosAsset[i]])
        }

        }, completionHandler: nil)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.