Created
February 10, 2015 17:25
-
-
Save benvium/6854ed90c5bc3861afdd to your computer and use it in GitHub Desktop.
NSPointerArray compact method that actually works.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSPointerArray (CALCompact) | |
- (void)cal_compact; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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