ฉันกำลังพยายามย้ายคลาส UIViewController
Objective-C ไปยัง Swift ตัวควบคุมมุมมองนี้สืบทอดมาจาก BaseViewController
โดยที่ฉันมีฟังก์ชันทั่วไปที่ฉันต้องการให้มีในตัวควบคุมทั้งหมด ปัญหาที่ฉันมีคือ myproject-Swift.h
ที่สร้างขึ้นไม่สามารถค้นหา BaseViewController
ของฉันได้
มีวิธีใดบ้างที่จะใช้ UIViewController
อย่างรวดเร็วซึ่งสืบทอดมาจาก BaseViewController
(คลาสย่อยของ UIViewController
) ที่เขียนใน Objective-C มีปัญหาเรื่องการตัดต่อหรือเปล่า?
สามารถทำซ้ำได้ด้วยโค้ดขั้นต่ำนี้:
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;
}
ชื่อโครงการ-Bridging-Header.h
#import "BaseViewController.h"