简体   繁体   English

在Objective-C项目中导入Swift框架-错误-未知类型名称

[英]Import Swift Framework in Objective-C Project - Error - Unknown Type Name

I've been wrestling with this specific issue for a while now. 我已经为这个特定问题努力了一段时间。 Basically I've added a framework BigNerdRanch CoreDataStack using Carthage . 基本上,我使用Carthage添加了一个框架BigNerdRanch CoreDataStack

But I've been having issues of using the said framework on my Objective-C codes. 但是我在我的Objective-C代码上使用上述框架时遇到了问题。 My project is an Objective-C project in which I recently added Swift codes and Swift frameworks. 我的项目是一个Objective-C项目,最近我在其中添加了Swift代码和Swift框架。

So far I've been able to use Swift frameworks in my Swift codes with no problems. 到目前为止,我已经能够在我的Swift代码中毫无问题地使用Swift框架。 But once I started using the said Swift frameworks on my old Obj-C, specifically AppDelegate.m, I keep getting compiler error no matter what. 但是一旦我开始在旧的Obj-C上使用上述Swift框架,特别是AppDelegate.m,无论如何我都会不断收到编译器错误。

From what I understand I have to import it like this: 据我了解,我必须像这样导入它:

#import <CoreDataStack/CoreDataStack-Swift.h>

In which I did on AppDelegate.m. 我在AppDelegate.m上做了。

I also have the following setup on my project: 我的项目中也有以下设置:

Project Target Setup: 项目目标设置:

在此处输入图片说明

Build Settings for Swift Compilation: Swift编译的构建设置:

在此处输入图片说明

I've been seeing some answers in StackOverflow to add public to the classes. 我一直在StackOverflow中看到一些答案,以将public添加到类中。 But I'm unable to do so since the imported Frameworks are self-contained and only contains Headers for me to see in the XCode project. 但是我无法这样做,因为导入的框架是独立的,并且只包含供我查看的XCode项目中的标头。

在此处输入图片说明

Thanks for the help guys. 感谢您的帮助。

You added a framework written in swift, if they don't enable support for Objective C , you can't use it in your objective c code. 您添加了一个快速编写的框架,如果它们不支持对Objective C支持,则不能在目标c代码中使用它。

However, you can create a class in swift, which will be used as a mediator between the framework and your ObjC classes. 但是,您可以快速创建一个类,该类将用作框架和ObjC类之间的中介。

@objc class coreDataStackConvertor: NSObject {

    func createStack(arg: Type) {

        // Code which uses the real CoreDataStack
    }

}

From you objective c classes, you can use the methods in the convertor class. 从目标c类中,您可以使用转换器类中的方法。

暂无
暂无

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

相关问题 错误消息“预期; 在顶级声明程序&#39;&#39;未知类型名称导入&#39;之后,使用桥在Objective-C中使用Swift - Error message 'Expected ; after top level declarator ' 'Unknown type name import' with the bridge to use Swift in Objective-C Swift - 导入Objective-C给出“未知类型名称” - Swift - Importing Objective-C Gives “Unknown type name” 将 iOS 框架(Swift/Objective-C)导入到 Android 应用程序项目中? - Import an iOS framework (Swift/Objective-C) into an Android app project? 无法在框架项目的 Objective-C 代码中导入 Swift 类 - Unable to import Swift class in Objective-C code in a framework project 将Objective-C Framework(CocoaPod)导入Swift? - Import Objective-C Framework (CocoaPod) into Swift? 使用Objective-C框架的Swift Project - Swift Project using objective-c framework 将 Swift 框架导入到 Objective-C 项目中 - importing swift framework into a objective-c project 添加一个Swift框架的Objective-C项目,可以导入桥头,但是显示未声明的swift类 - Objective-C project adding a Swift framework, can import bridge header, but it show undeclared swift class 尝试在Objective-C文件中使用swift类时未知类型名称“ Tester” - Unknown type name 'Tester' when trying to use swift class inside objective-c file 如何在Xcode Objective-C项目中的.mm类扩展中导入/使用快速静态库/框架 - How to import/use swift static library/framework in to .mm class extension in Xcode Objective-C Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM