I am trying to migrate a UIViewController
Objective-C class to Swift. This view controller is inheriting from a BaseViewController
where I have common functionality that I want to have in all controllers. The problem I am having is that the generated myproject-Swift.h
is not able to find my BaseViewController
.
Is there any way to implement a UIViewController
in swift that inherits from a BaseViewController
(subclass of UIViewController
) written in Objective-C? Is there a bridging problem?
It can be reproduced with this minimal code:
BaseViewController.h
#import <UIKit/UIKit.h>
@interface BaseViewController : UIViewController
@end
BaseViewController.m
import "BaseViewController.h"
@implementation BaseViewController
@end
ViewController.swift
import UIKit
class ViewController : BaseViewController {
}
AppDelegate.m
#import "AppDelegate.h"
#import "projectname-Swift.h" // Replace with your project name
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
projectname-Bridging-Header.h
#import "BaseViewController.h"