简体   繁体   English

使用未声明的类型错误:Swift

[英]Use of undeclared type error: Swift

I have some Objective-C files with defined classes. 我有一些带有定义类的Objective-C文件。

在此处输入图片说明

However when I try to create a instance of the class in Swift I get an error : 但是,当我尝试在Swift中创建类的实例时,出现错误: 在此处输入图片说明

What should I do to resolve this error? 我应该怎么做才能解决这个错误?

To be able to use Obj-C files from Swift project you should add Objective-C Bridging Header file. 为了能够使用Swift项目中的Obj-C文件,您应该添加Objective-C桥接头文件。 Create some h file and declare import statement for all necessary classes. 创建一些h文件并为所有必需的类声明import语句。 Then in build settings find Objective-C Bridging Header item and set the name of your file 然后在构建设置中找到“ Objective-C Bridging Header项并设置文件名

You are trying to merge Objective-C code with Swift . 您正在尝试将Objective-C代码与Swift合并。 Therefore, you should use Objective-C Bridging Header in between. 因此,您应该在两者之间使用Objective-C Bridging Header Detail information could be found in the official document: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html 可以在官方文档中找到详细信息: https : //developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM