美文网首页
OC创建的静态库与swift混编

OC创建的静态库与swift混编

作者: Cherry_06 | 来源:发表于2023-04-03 17:56 被阅读0次

本人使用的xcode版本为14.2

  1. 新建一个framework,语言勾选oc

  2. 将framework的类型改为static

  3. 创建swift文件,并写方法,注意添加@objc

import UIKit
import Foundation


@objc public class MySwiftClass: NSObject {
    @objc public func sayHello() {
        print("Hello from Swift")
       MyObjCClass().forSwift()
    }
}
  1. 选择target,在Objective-C Generated Interface Header Name填写OCAndSwiftFramework-Swift.h


    image.png
  2. 在需要调用swift代码的地方写上 #import "OCAndSwiftFramework/OCAndSwiftFramework-Swift.h"


    image.png

相关文章

网友评论

      本文标题:OC创建的静态库与swift混编

      本文链接:https://www.haomeiwen.com/subject/vwzdddtx.html