Пытаясь решить:
My AppDelegate
создает переменную-член something
, к которой мне нужен доступ в моей ViewDelegate
.
Моя реализация:
AppDelegate.h
#import <UIKit/UIKit.h>
#include "extern_lib.hpp"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (readwrite, nonatomic) some::Something *something;
@end
AppDelegate.mm
#import "AppDelegate.h"
#include "extern_lib.hpp"
@interface AppDelegate ()
@end
@implementation AppDelegate {
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_something = new some::Something();
return YES;
}
@end
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
ViewController.mm
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.something;
// use something
}
@end
extern_lib.hpp
#ifndef extern_lib_h
#define extern_lib_h
namespace some {
class Something {
public:
Something() {}
~Something() {}
};
}
#endif /* extern_lib_h */
Проблема:
Моя проблема в том, что компоновщик не находит базовые основные компоненты пользовательского интерфейса, и я 'Я действительно потерял, почему.
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_UIViewController", referenced from:
_OBJC_CLASS_$_ViewController in ViewController.o
"_OBJC_METACLASS_$_UIResponder", referenced from:
_OBJC_METACLASS_$_AppDelegate in AppDelegate.o
"_OBJC_CLASS_$_UIApplication", referenced from:
objc-class-ref in ViewController.o
"_OBJC_CLASS_$_UIResponder", referenced from:
_OBJC_CLASS_$_AppDelegate in AppDelegate.o
"_UIApplicationMain", referenced from:
_main in main.o
"_OBJC_METACLASS_$_UIViewController", referenced from:
_OBJC_METACLASS_$_ViewController in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)