如何在Swift项目中使用Objective-C框架类?

4

我开发了一个包含Swift和Objective-C文件的框架。当我在Swift项目中访问Swift类时,一切正常,但是当我尝试在Swift中访问Objective-C类时,我无法访问它,并且我也已经将Objective-C文件桥接到了Swift项目中。有人能帮我解决这个问题吗?

//swift project
import ObjCSwiftFramework

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let callingswiftfile = SwiftFile() //calling the swift file 
       let callingobjectivecfile = ObjectiveCFile()//**Use of unresolved identifier 'ObjectiveCFile'**

    }

}


//Bridge file
#ifndef ObjCSwift_project_Bridging_Header_h
#define ObjCSwift_project_Bridging_Header_h
#import "ObjCSwiftFramework/ObjCSwiftFramework.h"
#endif

我也附加了框架截图供您参考。enter image description here
2个回答

1

如果想在Swift中使用Objective-C文件,需要使用桥接头文件,然后只需按照以下方式导入类名即可:

桥接文件的名称类似于AppName-Bridging-Header.h

enter image description here

创建桥接头文件。

https://mycodetips.com/ios/manually-adding-swift-bridging-header-1290.html

文件添加和导入 obj-c 类后的外观
//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "CardIO.h"

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接