·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> oc和swift的混编

oc和swift的混编

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

参考:http://blog.sina.com.cn/s/blog_8d1bc23f0102v5tl.html

swift中使用oc类的方法

1.创建一个oc.h文件

 

2.添加需要倒入的oc类的头文件 

3.Bulid Settings中搜索bri,添加:$(SRCROOT)/$(TARGET_NAME)/oc.h

 

4.测试

 Test.h

#import <Foundation/Foundation.h>

@interface Test : NSObject

- (void)test;

@end

 Test.m

#import "Test.h"

@implementation Test

- (void)test {
    NSLog(@"这是一个测试");
}

@end

 ViewController.swift

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        var test: Test?   //声明
        test = Test()//初始化
        test?.test()//调用方法
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

 打印信息: