Skip to content

Instantly share code, notes, and snippets.

@danzimm
Last active September 25, 2016 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danzimm/2a72e0462d3d0744a9acd70898e36b8a to your computer and use it in GitHub Desktop.
Save danzimm/2a72e0462d3d0744a9acd70898e36b8a to your computer and use it in GitHub Desktop.
Objective-C++ object type helpers
template<typename T>
struct remove_ownership {
using type = T;
};
template<typename T>
struct remove_ownership<__strong T> {
using type = T;
};
template<typename T>
struct remove_ownership<__unsafe_unretained T> {
using type = T;
};
template<typename T>
struct remove_ownership<__weak T> {
using type = T;
};
template<typename T>
struct remove_ownership<__autoreleasing T> {
using type = T;
};
template<typename T, typename U>
T *objc_dynamic_cast(U *value) {
if ([value isKindOfClass:[T class]]) {
return (T *)value;
}
return nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment