The Bug
Shifting an NSMutableIndexSet by a negative number will drop an index in some cases.
Example Code:
NSMutableIndexSet *set = [NSMutableIndexSet indexSetWithIndex:0]; [set addIndex:2]; [set shiftIndexesStartingAtIndex:1 by:-1]; NSLog(@"%@", set);
The set should contain 0-1 but instead contains only 1.
The Reason
NSIndexSet is a series of NSRange-s. If the shift method removes empty space between ranges, than they should become a single unified range. For example, if a set contains the range 1-2 and the range 5-6, and we do
[set shiftIndexesStartingAtIndex:3 by:-2];
then we should get a set with a single range 1-4.
However, the implementation of shiftIndexesStartingAtIndex:by: fails to unify ranges, and also assumes that separate ranges have at least one empty space between them. And so we get a set containing the ranges 1-1 and 3-4.
The Workaround
Luckily, the methods addIndex: and addIndexesInRange: do correctly unify ranges. And so the workaround is to first call one of these methods, and only then shift:
[set addIndexesInRange:NSMakeRange(3, 2)]; [set shiftIndexesStartingAtIndex:3 by:-2];

The private API
Some actions may sometimes have more than one possible target, and other times only one.
Or picking an image. If you’re running on a camera-less iPod, you just show a UIImagePickerController to pick from the photo library. But with a camera, and maybe an existing image to delete, you’ll want to show an action sheet to choose the actual action that your “Photo” button performs.
I like the simple and straightforward interface of the Reminders.app: edit reminders inline, and add a reminder by tapping and typing in the next empty line. So I wrote a UITableViewController subclass that does just that, but adds Edit mode with reordering.
I know, I know – not another badge class! But the thing is, the other badges laying around the net all seem overly complicated and too inflexible. So yes, I wrote another badge class. Luckily, it was really easy because I used the built-in capabilities of iOS, and it turned out very flexible and powerful, because, well, I used the built-in capabilities of iOS. No manual CoreGraphics drawing code, just automatic CALayer-s magic.
There is an easy but little known way to store many kinds of UIKit objects in CoreData without writing any code. It works for UIImage, UIColor, UIBezierPath, MKPlaceMark, NSDate, and any other class that conforms to the NSCoding protocol.