oc和swift的混编

参考: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.
    }

}

 打印信息:

 

 

posted @ 2015-06-24 14:57  幻想无极  阅读(476)  评论(0编辑  收藏  举报