oc调用Swift的类,以及属性,方法
1.建一个OC工程命名为test2
2.新建一个swfit文件命名为SwiftTest.swift,会弹出提示,选择Create Bridging Header建立桥接文件,系统会建立“工程名-Bridging-Header.h”
3.配置工程
设置Defines Module 为Yes
设置Product Module Name 为当前工程名
此时系统会为工程创建一个“工程名-Swift.h”的文件,此文件不可手动创建,必须使用系统创建的
4.
5.创建一个.swift文件
import Foundation
@objcMembers public class hh:NSObject{
public func show(){
print("hello");
}
}
6.在OC文件中引用swift
#import "test2-Swift.h"
@interface ViewController ()
@property (nonatomic, strong) UIButton *button;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
{
hh *a = [[hh alloc]init];
[a show];