Created
May 31, 2017 14:33
-
-
Save steipete/624b4dbafc79d13ac8dade04f5eec407 to your computer and use it in GitHub Desktop.
Defer in ObjC. See more at https://pspdfkit.com/blog/2017/even-swiftier-objective-c
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
// Similar to defer in Swift | |
#define pspdf_defer_block_name_with_prefix(prefix, suffix) prefix ## suffix | |
#define pspdf_defer_block_name(suffix) pspdf_defer_block_name_with_prefix(pspdf_defer_, suffix) | |
#define pspdf_defer __strong void(^pspdf_defer_block_name(__LINE__))(void) __attribute__((cleanup(pspdf_defer_cleanup_block), unused)) = ^ | |
#pragma clang diagnostic push | |
#pragma clang diagnostic ignored "-Wunused-function" | |
static void pspdf_defer_cleanup_block(__strong void(^*block)(void)) { | |
(*block)(); | |
} | |
#pragma clang diagnostic pop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment