-
-
Save ricardopereira/e07ec9cfd2e54c52af75 to your computer and use it in GitHub Desktop.
Check if object is a block - nice for assertions.
This file contains 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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment