Skip to content

Instantly share code, notes, and snippets.

@marcinmatczuk
Created December 12, 2013 13:58
Show Gist options
  • Save marcinmatczuk/7928339 to your computer and use it in GitHub Desktop.
Save marcinmatczuk/7928339 to your computer and use it in GitHub Desktop.
A potential replacement for NSHashTable for iOS 5 - need to test it and see how it works with ARC.
/* Source: http://stackoverflow.com/questions/4692161/non-retaining-array-for-delegates/4692229#4692229 */
@implementation NSMutableArray (WeakReferences)
+ (id)mutableArrayUsingWeakReferences
{
return [self mutableArrayUsingWeakReferencesWithCapacity:0];
}
+ (id)mutableArrayUsingWeakReferencesWithCapacity:(NSUInteger)capacity {
CFArrayCallBacks callbacks = {0, NULL, NULL, CFCopyDescription, CFEqual};
// We create a weak reference array
return (id)(CFArrayCreateMutable(0, capacity, &callbacks));
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment