Skip to content

Instantly share code, notes, and snippets.

@wanderwaltz
Created March 30, 2013 06:42
Show Gist options
  • Save wanderwaltz/5275659 to your computer and use it in GitHub Desktop.
Save wanderwaltz/5275659 to your computer and use it in GitHub Desktop.
Non-retaining Cocoa containers from Three20.
static const void *TTRetainNoOp(CFAllocatorRef allocator,
const void *value) {return value;}
static void TTReleaseNoOp(CFAllocatorRef allocator,
const void *value) {}
NSMutableArray *TTCreateNonRetainingArray()
{
CFArrayCallBacks callbacks = kCFTypeArrayCallBacks;
callbacks.retain = TTRetainNoOp;
callbacks.release = TTReleaseNoOp;
return (NSMutableArray *)CFArrayCreateMutable(nil, 0, &callbacks);
}
NSMutableDictionary *TTCreateNonRetainingDictionary()
{
CFDictionaryKeyCallBacks keyCallbacks = kCFTypeDictionaryKeyCallBacks;
CFDictionaryValueCallBacks callbacks = kCFTypeDictionaryValueCallBacks;
callbacks.retain = TTRetainNoOp;
callbacks.release = TTReleaseNoOp;
return (NSMutableDictionary *)CFDictionaryCreateMutable(nil, 0,
&keyCallbacks, &callbacks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment