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

I'm looking for solutions to filter an array before a second treatment, which could be applied without further tests.

Say I want to delete all files greater than 500K from a given folder. I could:

1) get an enumerator, then for every item, test the size and remove big files; 2) get an enumerator, filter it, then remove all remaining files.

I'd like to know how to implement the solution 2. I'm thinking about another treatment (no deletion this time), like image reducing, which could be applied several times. At each loop, file sizes decrease, and the enumerator become always smaller, until it is empty. At this moment, the treatment is over.

But how to do this? I have seen numerous examples of predicates like @"SELF contains[c] 'e'"(with small variations) but never a SELF.size > 500000…

I suppose that the solution could be a block, but I have to confess that I'm completely lost...

A helping hand, please!

share|improve this question

1 Answer

How about using +[NSPredicate predicateWithBlock:] factory method? You would return YES for the items you want to keep (e.g. smaller than 500000 bytes/characters/…).

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.