Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if C-style function exists of type 'MyMethodName()'?

Tags:

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!

like image 215
Keller Avatar asked Sep 20 '12 17:09

Keller


1 Answers

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();
}
like image 198
Fabian Kreiser Avatar answered Oct 06 '22 00:10

Fabian Kreiser