Cocoa Warning: Implicitly declaring C library function ‘objc_getClass’

×

This post was originally published in 2011
It may contain stale & outdated information. Or it may have grown more awesome with age, like the author.

In Slider 2, I needed to check for the presence for Sparkle, and only load Slider 2′s included version when Sparkle isn’t found.

The code I used to do this is included below, but the point of this article is really to provide a solution to the following warning I encountered:

warning: Semantic Issue: Implicitly declaring C library function 'objc_getClass' with type 'id (const char *)'

One will get this warning if using code when checking for the existence of a class like:

if (!objc_getClass("SUUpdater")) { ... }

The solution is to use NSClassFromString instead:

if (!NSClassFromString(@"SUUpdater")) { ... }

For an in-depth tutorial on how to check for the presence of a framework within a Cocoa bundle, see Detecting Presence of a Framework Within an NSBundle (Plugin).

Comments (4) | Trackback