Skip to content

Instantly share code, notes, and snippets.

@numist
Last active December 25, 2015 06:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numist/6929738 to your computer and use it in GitHub Desktop.
Save numist/6929738 to your computer and use it in GitHub Desktop.
No clang diagnostic pragmas, the only trick is stuffing NSAutoreleasePool into a local to avoid the deprecation-under-ARC warning.
// Built for ARC, remove the __bridge and it should work in MRC as well.
void *NNCFAutorelease(CFTypeRef cfObject)
{
if (cfObject) {
static Class arp = Nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
arp = NSClassFromString(@"NSAutoreleasePool");
Assert(arp);
});
[arp addObject:(__bridge id)cfObject];
}
return (void *)cfObject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment