views:

937

answers:

3

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?

+7  A: 

It sounds like you probably need to

#import <SystemConfiguration/SystemConfiguration.h>
NilObject
Ah dangit not sure how I missed that, thanks NilObject.
Coocoo4Cocoa
+2  A: 

That error is almost always caused by the non-definition of the word preceding the error word (in this case, SCNetworkReachabilityRef preceding target).

Hence you have not defined SCNetworkReachabilityRef and (it looks like) all the other "SC..." types as well.

I'm not sure that SystemConfiguration.h is included in Reachability.h (if you're using the sample code from here).

That code includes both SystemConfiguration/SCNetworkReachability.h and Reachability.h.

paxdiablo
A: 

On iPhone, the 1.5 version of Apple's Reachability includes the

#import <SystemConfiguration/SystemConfiguration.h>

but you need to import the SystemConfiguration framework in your app. You can get it there /System/Library/Frameworks/SystemConfiguration.framework

Manuel Spuhler