It's easiest with a classic for
loop but since you want fast enumeration you need your own counter:
NSUInteger index = 0;
NSUInteger count = objects.count;
for (id obj in objects) {
if (index == 0) {
// first
} else if (index == count - 1) {
// last
} else {
// all others
}
index++;
}
If objects
is an NSArray
, you can do:
[objects enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (idx == 0) {
// first
} else if (idx == objects.count - 1) {
// last
} else {
// all others
}
}];