可达性ld:重复符号_OBJC_IVAR _ $ _ Reachability.localWiFiRef

1 symbols objective-c duplicates reachability

我包括"Reachability/Reachability.m"

AppDelegate.h

#import <UIKit/UIKit.h>
#import "Reachability/Reachability.m"

@class ...;

@interface ... : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    ... *viewController;
    Reachability *hostReach;
    NetworkStatus netStatus;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic) NetworkStatus netStatus;
-(void)updateInterfaceWithReachability: (Reachability*) curReach;

@end


AppDelegate.m


#import "AppDelegate.h"
#import "ViewController.h"

@implementation ...

@synthesize window=_window;
@synthesize navigationController=_navigationController;
@synthesize netStatus;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
    hostReach = [[Reachability reachabilityWithHostName:@"www.apple.com"]retain];
    [hostReach startNotifier];
    [self updateInterfaceWithReachability:hostReach];


    // Set the view controller as the window's root view controller and display.
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

ld: duplicate symbol _OBJC_IVAR_$_Reachability.localWiFiRef in /Users/../Documents/../build/.. .build/Debug-iphonesimulator/.. .build/Objects-normal/i386/..ViewController.o and /Users/../Documents/../build/.. .build/Debug-iphonesimulator/.. .build/Objects-normal/i386/..AppDelegate.o

Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题呢?它可能有什么关系?

Tim*_*her 5

我遇到了同样的问题,因为我正在使用的一个第三方库(libPusher)已经包含了Reachability.

由于该库是预编译的,我不知道该怎么做,但只添加Reachability.h到项目(而不是Reachability.m)工作.这允许我导入它并使用该类,但我没有重复的符号问题.