Swift5-swift和oc混编

2020-05-19  本文已影响0人  Jesscia_Liu

Tips:swift项目和oc项目中swift和oc混编做法一样
本文中项目名为Test,即Build Settings中Product Name配置为Test

productName

一、swift中调用oc类

//Test-Bridging-Header.h
#import "MyViewh"
import UIKit
class TestViewController: UIViewController {
    func testOC(){
        let tmpV = MyView()
        tmpV.test1()
        self.view.addSubview(tmpV)
    }
}

二、oc中调用swift类

#import "MyView.h"
#import "Test-Swift.h"  //ProductName-Swift.h

@implementation MyView

- (void)test1{
    testSwiftView *view = [[testSwiftView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
    view.backgroundColor = [UIColor redColor];
    [self addSubview:view];
}
@end

三、检查Build Settings配置

Build Settings配置
上一篇下一篇

猜你喜欢

热点阅读