简体   繁体   中英

Multiple ViewController inheritance causes Apple Mach-O Linker Error

I'm setting up a base view controller called "BHAccountBaseViewController" and two other views that inherit from some basic functionality from the base controller.

  1. "BHAccountBaseViewController" Inherits from "UIViewController"
  2. "BHAccountViewController" (implements UITextFieldDelegate) and Inherits from "BHAccountBaseViewController"
  3. Lastly I have one recently created class that I called "BHCreateProfileViewController" every time that I just simply include #import directive to "BHAccountBaseViewController" to inherit from this class Xcode fails to compile due to APPLE MACH-O LINKER ERROR!

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

Thoughts? these are my three header files

BHAccountBaseViewController

#import <UIKit/UIKit.h>
#import "BHFileManager.h"

@interface BHAccountBaseViewController : UIViewController
@end

BHAccountViewController

#import "BHAccountBaseViewController.h"
@interface BHAccountViewController : BHAccountBaseViewController<UITextFieldDelegate>
@end

BHCreateProfileViewController

#import "BHAccountBaseViewController.m"
@interface BHCreateProfileViewController : UIViewController <UITextFieldDelegate>
@property (strong, nonatomic) id user;
@end

if I comment out the import on the last file the linker error goes a way! but I want to be able to inherit from my base clase ... thoughts?

Help would be much appreciated!

In implementation of BHCreateProfileViewController given above, I found the code looks like getting wrong at first line. What about fixing it as following:

#import "BHAccountBaseViewController.m"

to

#import "BHAccountBaseViewController.h"

and I wonder why BHCreateProfileViewController comes to inherit from UIViewController not BHAccountBaseViewController. Could you explain that?

This might be due to the retain cycle deadlock problem. You have to use forward class declaration for this ie you can try @Class instead of #import. Please refer to these limks :

Objective-C: Forward Class Declaration

@class vs. #import

These might help.

In the compilation time your compiler would actually look for your interface files instead of implementation file.Compiler does not bother even if .m file is not available. So while importing you are supposed to import .h instead .m.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM