ios - 如何在swift项目中使用objective c框架类?
问题描述
当我开发同时具有 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
解决方案
要在 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"
推荐阅读
- security - 如何在 VSCode 中禁用 `vscode://` URI 安全提示?
- java - Guava Table:当高度和宽度未知且表稀疏时如何迭代列
- anylogic - 我的anylogic中的字符错误,它们随着以下两个字符而变化,我该怎么办?
- java - 如何通过已经在 Postman 中工作并且 nginx 服务器没有限制的改造发送大文件图像?
- javascript - 为什么我不能将我的 javascript 变量设置为 false?
- r - 如何解决操作中的download.file错误超时?
- python - 在用 python 编码的 Apache-Beam 管道中提供 BigQuery 凭据
- python - 我可以用 os.system 或 os.startfile 打开什么类型的文件?
- flutter - 如何在颤动中使用带有资产的carousel_slider
- android - java.lang.NoClassDefFoundError:解析失败:Lcom/android/volley/VolleyLog;