Skip to content

Instantly share code, notes, and snippets.

@leilee
Last active September 15, 2017 05:51
Show Gist options
  • Select an option

  • Save leilee/cef4fd0b3d5ba30b945aef94f47984f7 to your computer and use it in GitHub Desktop.

Select an option

Save leilee/cef4fd0b3d5ba30b945aef94f47984f7 to your computer and use it in GitHub Desktop.
OBJC_DYNAMIC_CAST
auto a = [NSMutableArray array];
if (auto array = OBJC_DYNAMIC_CAST(a, NSArray))
{
// blablabla
}
#if !defined(OBJC_DYNAMIC_CAST)
#define OBJC_DYNAMIC_CAST(OBJECT, TYPE) ({ id obj=OBJECT;[obj isKindOfClass:[TYPE class]] ? (TYPE *) obj: nil; })
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment