简体   繁体   中英

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 .

But I've been having issues of using the said framework on my Objective-C codes. My project is an Objective-C project in which I recently added Swift codes and Swift frameworks.

So far I've been able to use Swift frameworks in my Swift codes with no problems. 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.

From what I understand I have to import it like this:

#import <CoreDataStack/CoreDataStack-Swift.h>

In which I did on AppDelegate.m.

I also have the following setup on my project:

Project Target Setup:

在此处输入图片说明

Build Settings for Swift Compilation:

在此处输入图片说明

I've been seeing some answers in StackOverflow to add public to the classes. 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.

在此处输入图片说明

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.

However, you can create a class in swift, which will be used as a mediator between the framework and your ObjC classes.

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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