Skip to content

Instantly share code, notes, and snippets.

@pmj
Created June 17, 2012 15:36
Show Gist options
  • Save pmj/2944868 to your computer and use it in GitHub Desktop.
Save pmj/2944868 to your computer and use it in GitHub Desktop.
Safe Objective-C cast with superclass type check
#define SSDC_CAST(TYPE, EXPR) \
({ \
__typeof(EXPR) _cast_expr_tmp = (EXPR); \
__typeof(EXPR) _super_check_ref __attribute__((unused)) = (TYPE*)nil; \
([_cast_expr_tmp isKindOfClass:[TYPE class]]) ? (TYPE*)_cast_expr_tmp : nil; \
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment