简体   繁体   English

添加Swift文件后构建Swift Cocoa Touch Framework时出错: <unknown> :0:错误:无法构建Objective-C模块

[英]Error building Swift Cocoa Touch Framework after adding Swift file: <unknown>:0: error: could not build Objective-C module

I have a problem creating a Swift Cocoa Touch Framework. 我在创建Swift Cocoa Touch Framework时遇到问题。 As soon as I add my first .swift file, clean, then build I get a build error: 只要我添加我的第一个.swift文件,清理,然后构建我得到一个构建错误:

<unknown>:0: error: could not build Objective-C module 'MyTextFramework'

This is easily reproducible from scratch in just a few steps using Xcode 6.1.1 使用Xcode 6.1.1,只需几步即可轻松重现

  • Create new Cocoa Touch Framework using Swift Language 使用Swift语言创建新的Cocoa Touch Framework
  • Add an iOS swift file 添加iOS swift文件
  • Build - OK 建立 - 好的
  • Clean - OK 清洁 - 好的
  • Build - ERROR 构建 - 错误
  • From here on the project will not build unless I delete the swift file. 从这里开始,除非我删除swift文件,否则不会构建项目。

I've tried the typical Xcode magic such as deleting derived data, restarting Xcode, etc. 我尝试了典型的Xcode魔术,例如删除派生数据,重启Xcode等。


Steps detailed below with screenshots: 以下详细步骤截图:

File > New > Project > iOS Framework & Library > Cocoa Touch Framework 文件>新建>项目> iOS框架和库> Cocoa Touch Framework 在此输入图像描述

Product Name: MyTextFramework 产品名称:MyTextFramework

Language: Swift 语言:斯威夫特 在此输入图像描述

I now have a bare bones Cocoa Touch Framework. 我现在有一个简单的Cocoa Touch Framework。 在此输入图像描述

Add an iOS Swift file named FooBaz.swift 添加一个名为FooBaz.swift的iOS Swift文件

Add a class that extends NSObject and an init function. 添加一个扩展NSObject和init函数的类。

The target still builds fine at this point. 此时目标仍然很好。 在此输入图像描述

Cmd-K to clean the project Cmd-K清理项目

Cmd-B to build again... BAM Cmd-B再次建造...... BAM 在此输入图像描述

如果您不打算使用Objective-C中的Swift框架,最简单的解决方案是摆脱MyTextFramework.h

As Georg Tuparev answered, I just need to remove MyTextFramework.h and it builds fine. 正如Georg Tuparev回答的那样,我只需要删除MyTextFramework.h就可以了。 However, this prevents using my framework in Obj-C code. 但是,这可以防止在Obj-C代码中使用我的框架。

Is it even possible to build a framework containing Swift code that can be used in both Swift AND Obj-C? 甚至可以构建一个包含可以在Swift和Obj-C中使用的Swift代码的框架吗? If it is technically possible, then it seems this issue with Xcode would prevent anyone from actually doing it. 如果技术上可行,那么Xcode的这个问题似乎会阻止任何人实际做到这一点。 Does anyone have any comments or solutions for this scenario? 有没有人对此方案有任何意见或解决方案?

暂无
暂无

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

相关问题 包含框架时,Swift导入出现错误“无法构建目标C模块&#39;Twitter&#39;” - Swift import got error “Could not build objective-C module 'Twitter'” while including a framework Cocoa Touch Objective-C框架中的Swift类 - Swift class in Cocoa Touch Objective-C Framework 在Swift项目中使用CocoaPods作为模块添加Objective-C框架项目时,找不到iOS模块错误 - IOS Module not found error when adding Objective-C framework projects using CocoaPods as a module in Swift project 在Swift内的objective-c框架中没有这样的模块错误 - No Such Module error in objective-c framework inside Swift Xcode 8.0 swift 3.0 错误 Alamofire-swift.h 未找到且无法构建 Objective-C 模块“Alamofire” - Xcode 8.0 swift 3.0 error Alamofire-swift.h not found and Could not build Objective-C module 'Alamofire' 在Swift项目(Empatica)中使用Objective-C框架文件时出现奇怪的生成错误 - Strange build error when using Objective-C framework file in Swift project (Empatica) Swift 4 + Xcode 9 +无法构建Objective-C模块&#39;FBSDKLoginKit&#39; - Swift 4 + Xcode 9 + Could not build Objective-C module 'FBSDKLoginKit' 将Swift导入Objective-c后出现错误 - error after importing Swift into Objective-c 在 objective-c 模块中使用 swift 时无法构建 Objective-C 模块 - Could not build Objective-C module, when using swift in objective-c module 从Single View Application(objective-c)以函数作为Cocoa Touch Framework(swift)的参数的调用方法 - Call method with function as argument of Cocoa Touch Framework (swift) from Single View Application (objective-c)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM