swift与oc的代码是可以互相调用的

创建一个类 继承自nsobject 随后在,h文件中声明一个方法,随后再.m文件中实现这个方法 在桥接文件中 添加进这个文件的头文件 随后就可以直接在swift的代码中调佣这个OC的代码

ios oc调用swift方法 swift调用oc类方法_ide

在.h文件中

#import <Foundation/Foundation.h>

@interface sayHello : NSObject
-(void)sayHello;
@end



在.m文件中

#import "sayHello.h"

@implementation sayHello
-(void)sayHello{
    NSLog(@"cao");
}
@end



随后再桥接文件中

#include"sayHello.h"



随后就可以直接在view controller中调佣这个类了

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
      let h = sayHello()
        h.sayHello()
        
    }

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


}