I use AppCode to tweak the code I've written in XCode. AppCode does awesome code inspections, and tells you where things can be improved.
One of the frequent inspections I come across points out that [SomeObjCFrameworkClass objectAtIndex] is expecting an NSUInteger which is in fact true...
- (ObjectType)objectAtIndex:(NSUInteger)index
however, I keep finding myself getting screwed by trying to follow this advice and change my ints to NSUIntegers.
For example, here's one piece of code that exploded when I did this change...
-(void)removeBadge
{
if ([[theButton subviews] count]>0)
{
NSUInteger initalValue = [[theButton subviews] count]-1;
//Get reference to the subview, and if it's a badge, remove it from it's parent (the button)
for (NSUInteger i=initalValue; i>=0; i--) {
if ([[[theButton subviews] objectAtIndex:i] isMemberOfClass:[MKNumberBadgeView class]])
{
[[[theButton subviews] objectAtIndex:i] removeFromSuperview];
[theButton setTitleColor:[UIColor lightTextColor] forState:UIControlStateNormal];
}
}
}
}
Any idea why this is happening. There is a clue in the debug data pictured below, but I can't make sense of it.

NSUInteger in unsigned, so
i>=0condition in yourforloop always evaluates toYES. Afterireach 0, on next iteration you will get integer underflow, andibecomesNSUIntegerMax.Updated: As far as I can tell from your code, there is no reason in processing subviews in reverse order. So, you can simply do
Otherwise, you can use something like
inside your loop or use
do/whilefor example.