Objective-C: Why am I getting a compile error when importing a header file

cocoacocoa-touchiphoneobjective c

I'm curious what some reasons might be as to getting a compiler error for simply importing a header file. If I comment it out, everything compiles just fine — the header/implementation for the class I'm trying to import into one of my UIViewController's get passed the compiler without any warnings. However, as soon as I include it, I get a multitude of errors.

I'm trying to use Apple's Reachability app in my own code, and by doing something like:

#import "Reachability.h"

I get a ton of:

error: syntax error before 'target'
error: syntax error before 'SCNetworkReachabilityFlags'
error: syntax error before 'SCNetworkReachabilityRef'
error: syntax error before 'SCNetworkReachabilityRef'
fatal error: method definition not in @implementation context

It's mostly complaining regarding:

static void ReachabilityCallback(SCNetworkReachabilityRef target,       SCNetworkReachabilityFlags flags, void *info);
- (BOOL)isNetworkAvailableFlags:(SCNetworkReachabilityFlags *)outFlags;
- (SCNetworkReachabilityRef)reachabilityRefForHostName:(NSString *)hostName;
- (CFRunLoopRef)startListeningForReachabilityChanges:(SCNetworkReachabilityRef)reachability onRunLoop:(CFRunLoopRef)runLoop;

Any idea why this is only happening when I try to import the header file?

Best Answer

It sounds like you probably need to

#import <SystemConfiguration/SystemConfiguration.h>
Related Topic