List not filled?

NSPredicate *mp = [NSPredicate predicateWithFormat: @“SELF contains[c] ‘.jpg’”];
NSArray *list = [NSArray arrayWithArray:[[[manager enumeratorAtPath:thePath]allObjects] filteredArrayUsingPredicate: mp]];
for (id aPath in list){
[self.gList addObject:[NSString stringWithString:@“Hello”]];
NSLog(@“Add”);
}
NSLog(@“%ld”,[self.gList count]);

The log console says “Add” the correct number of times.

When I log the count of my NSMutableArray, it is zero.

Can someone explains this?

There’s nothing wrong with what you posted, so the problem must lie elsewhere. I’m guessing that you forgot to initialize gList. BTW, there’s no reason to use stringWithString like this:

[self.gList addObject:[NSString stringWithString:@"Hello"]];

You just need:

[self.gList addObject:@"Hello"];

Ric

Hi Ric,

You’re right, I forgot to initialize the list (alloc). I still have to understand what “synthesize” does exactly: it’s just a compiler facility to generate code for setters and getters, it does not initialize anything. Regarding IB objects, they ARE initialized when the nib is loaded. But my list had no blue cube, it’s just a property.

For the rest, I now use brute force so:

and use a ValueTransformer to put the image file into the list. Works fine. But for two hours, I regretted not having chosen to make macramé instead of programming.

Thanks!

You might want to look at pathsMatchingExtensions:. It’s case-sensitive, but less work than a predicate.

I also wonder why you’re using enumeratorAtPath: … allObjects, rather than subpathsAtPath:. Could it be a macramé thing? :wink:

Hi Shane,

Because some files have “.JPG” extensions (my camera is to blame for this). And because I’m fond of predicates since StefanK told me about these filters. :slight_smile:

No, that’s because I don’t read the docs carefully enough, which makes me write a lot of useless code. :confused:

Thank you for the subpathsAtPath method! Works fine, I should end with a one-liner.

But you’re checking against a list, so you can include jpg and JPG.