【问题标题】:how to use the objective c framework class in swift project? [duplicate]如何在swift项目中使用objective c框架类? [复制]
【发布时间】:2018-11-07 15:19:47
【问题描述】:

当我开发同时具有 swift 和目标 c 文件的框架时。当我在 swift 项目中访问 swift 类时,它工作正常,但是当我尝试在 swift 中访问目标 c 类时,我无法访问我还在swift项目中桥接了目标c文件。任何人都可以帮我解决上述问题。

//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

我还添加了框架屏幕截图供您参考

【问题讨论】:

    标签: ios objective-c frameworks


    【解决方案1】:

    要在 swift 中使用 Objective-c 文件,您需要使用 Bridging header,现在只需在其中导入类名,如下所示

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

    创建桥接头

    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"
    

    【讨论】:

      【解决方案2】:

      您需要使用桥接头。要了解如何创建桥接头,请使用以下链接

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-18
        • 2020-10-29
        • 1970-01-01
        • 1970-01-01
        • 2015-12-04
        • 2018-09-17
        相关资源
        最近更新 更多