xcode Swift 导入语句失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27414202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swift import statement failing
提问by David
UPDATED with answer at bottom
更新底部的答案
I am using the TwitterKit framework as installed with Twitter's new Fabric platform. This code in ViewController.swift
works just fine:
我使用 TwitterKit 框架与 Twitter 的新 Fabric 平台一起安装。这段代码ViewController.swift
工作得很好:
//
// ViewController.swift
// Following
//
// Created by David Aragon on 12/4/14.
// Copyright (c) 2014 David Aragon. All rights reserved.
//
import UIKit
import TwitterKit
But this code in a custom Swift file I made called TwitterAdapter.swift
fails:
但是我创建的自定义 Swift 文件中的这段代码TwitterAdapter.swift
失败了:
//
// TwitterAdapter.swift
// Following
//
// Created by David Aragon on 12/10/14.
// Copyright (c) 2014 David Aragon. All rights reserved.
//
import Foundation
import TwitterKit // Error: No such module 'TwitterKit'
I made sure to add TwitterAdapter.swift
to all my targets when I created it. Here are some screen shots to illuminate the directory hierarchy:
TwitterAdapter.swift
当我创建它时,我确保添加到我的所有目标中。以下是一些说明目录层次结构的屏幕截图:
UPDATE:
更新:
Solved with the latter portion of Kampai's answer. Here is the part that got it all working:
用 Kampai 答案的后一部分解决了。这是让它全部工作的部分:
Again right click on the project name and click on Add files to "project-name" >> Select TwitterKit.framework bundle and click on Add button will add a reference of that framework to project.
再次右键单击项目名称,然后单击将文件添加到“项目名称”>> 选择 TwitterKit.framework 包并单击“添加”按钮将向项目添加该框架的引用。
采纳答案by Kampai
Here I have tried to add this framework in application and its perfectly working. From this it is clear that issue is related to linking with the module you have added.
在这里,我尝试在应用程序中添加这个框架并且它完美地工作。由此可见,问题与与您添加的模块的链接有关。
Relink / Reference again with the module will resolve this issue:
再次与模块重新链接/引用将解决此问题:
Points need to be highlight:
需要强调的点:
- Copy the framework to project application folder.
- 将框架复制到项目应用程序文件夹。
For example:
例如:
Go to finder of its location >> From Xcode right click on project name >> Show in finderwill open project location folder. Here you must have to copy TwitterKit.framework
bundle.
转到其位置的查找器>>从Xcode右键单击项目名称>>在查找器中显示将打开项目位置文件夹。在这里你必须复制TwitterKit.framework
捆绑。
- Again right click on the project name and click on Add files to "project-name">> Select
TwitterKit.framework
bundle and click on Addbutton will add a reference of that framework to project.
- 再次右键单击项目名称,然后单击将文件添加到“项目名称”>> 选择
TwitterKit.framework
包并单击添加按钮将对该框架的引用添加到项目中。
回答by Tim
回答by rakita
I was facing the same problem. My project was swift based and there were no objective C code. I wanted to add 3rd party framework and on import facing same error "no such module". I solved it by adding a bridging-header file in swift and just import framework there. It works for me.
我面临着同样的问题。我的项目基于 swift 并且没有客观的 C 代码。我想添加第 3 方框架并在导入时面临同样的错误“没有这样的模块”。我通过在 swift 中添加桥接头文件并在那里导入框架来解决它。这个对我有用。