Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Trying to remove the objects from NSMutableArray, below is how addition done to array.

sectionInfo = [self.collectionView indexPathsForSelectedItems];

How tried to remove

[sectionInfo removeAllObjects];

The error i got is unrecognized selector sent to instance 0x169cfb70. I think it's because i didn't added items in to array ass addObject: but that's not my requirement. So, how to manage this.

share|improve this question
1  
Is section info is an NSMutable array? – Augustine P A May 27 at 5:43

3 Answers

up vote 1 down vote accepted

The indexPathsForSelectedItems returns an immutable NSArray, regardless of how sectionInfo was declared. Theoretically you could do:

sectionInfo = [[self.collectionView indexPathsForSelectedItems] mutableCopy];

Or, if you're just trying to reset sectionInfo, you can leave the declaration of sectionInfo alone, but then rather than removeAllObjects, you could simply say:

sectionInfo = nil;

Or create a new array:

sectionInfo = [NSMutableArray array];

I guess it comes down to why you're trying to remove objects from sectionInfo, rather than just resetting it.

share|improve this answer

The problem is that -[UICollectionView indexPathsForSelectedItems] doesn't return a NSMutableArray. You want to convert it to a NSMutableArray before trying to modify it:

sectionInfo = [NSMutableArray arrayWithArray: [self.collectionView indexPathsForSelectedItems]];
share|improve this answer

Make a mutable copy of the indexPathsForSelectedItems . Because indexPathsForSelectedItems returns NSArray not NSMutableArray. NSArray doesn't have removeAllObjects method.

sectionInfo = [[self.collectionView indexPathsForSelectedItems]mutableCopy];
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.