Created
January 12, 2016 21:56
-
-
Save steipete/6ee378bd7d87f276f6e0 to your computer and use it in GitHub Desktop.
Check if object is a block - nice for assertions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} |
Licensed under MIT. Feel free to use.
Thanks for the prompt reply!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Peter, is there a license that you wish to use for this code?
Thanks