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];
}
@hrieke
Copy link

hrieke commented Dec 30, 2024

Hi Peter, is there a license that you wish to use for this code?
Thanks

@steipete
Copy link
Author

Licensed under MIT. Feel free to use.

@hrieke
Copy link

hrieke commented Dec 30, 2024

Thanks for the prompt reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment