If ARC is enabled, your Objective-C object pointer variables will be set to zero regardless of where you create them. [Source]
If you are not using ARC, you can explicitly point to nil:
NSArray *items;
NSObject *item = nil;
for (item in items) {
if (item matches some criterion) {
break;
}
}
if (item) {
}
else {
}
I don’t know the specific case, but could you just do this by doing the work inside the for loop:
NSArray *items;
NSObject *item;
for (item in items) {
if (item matches some criterion)
{
break;
}
}
source
share