简体   繁体   English

No Such Module'Insembles'错误 - 导入objective-c框架以在swift项目中使用

[英]No Such Module 'Ensembles' Error - importing objective-c framework to use in swift project

I am add Ensembles to my Swift project - found here https://github.com/drewmccormack/ensembles . 我将Ensembles添加到我的Swift项目中 - 在这里找到https://github.com/drewmccormack/ensembles I have had no luck adding iCloud support to my app and syncing data across devices so hoping this will work. 我没有运气添加iCloud支持到我的应用程序和跨设备同步数据,所以希望这将工作。

I have followed the following instructions for adding the framework to my app, 我已按照以下说明将框架添加到我的应用程序,

  1. In Finder, drag the Ensembles iOS.xcodeproj project from the Framework directory into your Xcode project. 在Finder中,将Ensembles iOS.xcodeproj项目从Framework目录拖到Xcode项目中。
  2. Select your App's project root in the source list on the left, and then select the App's target. 在左侧的源列表中选择应用程序的项目根目录,然后选择应用程序的目标。
  3. In the General tab, click the + button in the Linked Frameworks and Libraries section. 在“常规”选项卡中,单击“链接的框架和库”部分中的+按钮。
  4. Choose the libensembles.a library and add it. 选择libensembles.a库并添加它。
  5. Select the Build Settings tab. 选择“构建设置”选项卡。 Locate the Other Linker Flags setting, and add the flag -ObjC. 找到Other Linker Flags设置,并添加标志-ObjC。

    This is how it looks in my project, I am unsure if i have done this step right. 这就是它在我的项目中的样子,我不确定我是否已经做好了这一步。

在此输入图像描述

  1. Select the Build Phases tab. 选择Build Phases选项卡。 Open Target Dependencies, and click the + button. 打开Target Dependencies,然后单击+按钮。
  2. Locate the Ensembles Resources iOS product, and add that as a dependency. 找到Ensembles Resources iOS产品,并将其添加为依赖项。
  3. Open the Ensembles iOS.xcodeproj project in the source list, and open the Products group. 在源列表中打开Ensembles iOS.xcodeproj项目,然后打开Products组。
  4. Drag the Ensembles.bundle product into the Copy Bundle Resources build phase of your app. 将Ensembles.bundle产品拖到应用程序的Copy Bundle Resources构建阶段。
  5. Add the following import in your precompiled header file, or in any files using Ensembles. 在预编译头文件或使用Ensembles的任何文件中添加以下导入。

It is step 10 that I am having problems with. 我遇到问题是第10步。 Do I have to create a bridging header or just import the framework into my swift files ? 我是否必须创建桥接头或只是将框架导入我的swift文件?

This is how I am importing within my CoreDataStack.swift file 这是我在CoreDataStack.swift文件中导入的方式

import UIKit
import CoreData
import Ensembles

class CoreDataStack: NSObject, CDEPersistentStoreEnsembleDelegate {

}

This gives me the error; 这给了我错误;

No such module 'Ensembles' 没有这样的模块'Ensembles'

I tried creating a bridging header by doing the following; 我尝试通过执行以下操作创建桥接标头;

  • Add new header file 添加新的头文件
  • Import Ensembles 导入合奏

This is how that looks; 这是看起来如何;

#ifndef Header_h
#define Header_h
#import <Ensembles/Ensembles.h>

#endif /* Header_h */

But still no luck, does anybody know where I am going wrong when trying to import the framework to use with my swift project ? 但是仍然没有运气,在尝试导入框架以使用我的swift项目时,是否有人知道我哪里出错了?

When creating a bridging header you do not need to use import. 创建桥接头时,您不需要使用导入。

However I don't think you may be adding a bridging header correctly, go to, file, new, file, add a objective-C file and a dialog should pop up asking if you want to create a bridging header. 但是我不认为你可能正确地添加了一个桥接头,转到,文件,新建,文件,添加一个Objective-C文件,然后会弹出一个对话框,询问你是否要创建一个桥接头。 Add both files but delete the objective-C file and keep the bridging header. 添加两个文件但删除objective-C文件并保留桥接标头。

Then import the ensembles framework to the bridging header like so. 然后将ensembles框架导入桥接头,就像这样。

#import <Ensembles/Ensembles.h>

When creating a bridging file successfully you should not need to import the framework in your swift files and it should be available throughout your project. 成功创建桥接文件时,您不需要在swift文件中导入框架,它应该在整个项目中可用。 See this post for more information - Connect Objective C framework to Swift iOS 8 app (Parse framework) 有关更多信息,请参阅此文章 - 将Objective C框架连接到Swift iOS 8应用程序(Parse框架)

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

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