[英]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.