This question is geared for iOS version compatibility.
I know how to check if a function exists if it is a typical Objective-C style method using respondsToSelector. i.e. For a method such as:
- (void) someMethod:(NSInteger)someParameter;
You can use:
if ([self respondsToSelector:@selector(someMethod:someParameter)]) {
//do something
}
But what about C-style functions? How can I check if a function exists that looks like:
void CStyleFunctionName(FoundationTypeRef parameter);
Thanks!
Xcode (at least since 4.3) supports weak linking and you can do the following to see if you can call a C function:
// UIGraphicsBeginImageContextWithOptions() was introduced in iOS 4 in order to support the Retina displays.
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(...);
}
else {
UIGraphicsBeginImageContext();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With