Skip to content

Instantly share code, notes, and snippets.

@benvium
Created February 10, 2015 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benvium/6854ed90c5bc3861afdd to your computer and use it in GitHub Desktop.
Save benvium/6854ed90c5bc3861afdd to your computer and use it in GitHub Desktop.
NSPointerArray compact method that actually works.
#import <Foundation/Foundation.h>
@interface NSPointerArray (CALCompact)
- (void)cal_compact;
@end
#import "NSPointerArray+CALCompact.h"
@implementation NSPointerArray (CALCompact)
- (void) cal_compact {
// NSPointerArray.compact doesn't work..! Should remove null entries but doesn't!
// workaround from https://gist.github.com/sberan/6342401d78674c3831ba
for (NSInteger i = self.count - 1; i >= 0; i--) {
id obj = [self pointerAtIndex:(NSUInteger) i];
if (!obj) {
[self removePointerAtIndex:(NSUInteger) i];
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment