Search code examples
iosxcodelinker-errorsduplicate-symbol

Unknown Xcode Error: linker command failed with exit code 1 (use -v to see invocation)


I keep getting this error but I have no idea where it's coming from.

linker command failed with exit code 1 (use -v to see invocation)

enter image description here

How do I fix this?

Here's the code from WebView.m

 #import "WebViewController1.h"

    @interface ViewController ()

    @property (strong, nonatomic) IBOutlet UIWebView *webView;
    @property (weak, nonatomic) IBOutlet UIWebView *webView2;

    @end

    @implementation ViewController

Here's the code from WebViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end

Solution

  • You have done one of two things wrong here.

    You either mistakenly imported ViewController.m (instead of ViewController.h) into WebView.m. Or your WebView.h and .m mistakenly declare the ViewController class instead of the WebView class.

    Based on the comments and the updated question it seems to be latter problem.

    Both ViewController.h/.m and WebView.m/WebViewController.h declare the class ViewController.

    1. You really need to give your .h and .m files the same name. I would suggest renaming WebView.m to WebViewController.m. It makes things a lot clearer if the .h and .m for a class are the same and have the same name as the class.
    2. Fix WebViewController.h so you declare WebViewController instead of ViewController:

      @imterface WebViewController : UIViewController
      
    3. Fix WebViewController.m (the former WebView.m so you define WebViewController instead of ViewController.

      #import "WebViewController.h"
      
      @interface WebViewController ()
      
      @property (strong, nonatomic) IBOutlet UIWebView *webView;
      @property (weak, nonatomic) IBOutlet UIWebView *webView2;
      
      @end
      
      @implementation WebViewController