Last active
September 25, 2016 17:15
-
-
Save danzimm/2a72e0462d3d0744a9acd70898e36b8a to your computer and use it in GitHub Desktop.
Objective-C++ object type helpers
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
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