Skip to content

Instantly share code, notes, and snippets.

@steipete
Created January 12, 2016 21:56
Show Gist options
  • Save steipete/6ee378bd7d87f276f6e0 to your computer and use it in GitHub Desktop.
Save steipete/6ee378bd7d87f276f6e0 to your computer and use it in GitHub Desktop.
Check if object is a block - nice for assertions.
PSPDF_EXTERN BOOL PSPDFIsBlock(id _Nullable block) {
static Class blockClass;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
blockClass = [^{} class];
while ([blockClass superclass] != NSObject.class) {
blockClass = [blockClass superclass];
}
});
return [block isKindOfClass:blockClass];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment