将Project-Swift.h导入到Objective-C类...找不到文件 [英] Importing Project-Swift.h into a Objective-C class...file not found

查看:96
本文介绍了将Project-Swift.h导入到Objective-C类...找不到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Objective-C中启动的项目,我正在尝试将一些Swift代码导入到我之前编写的Objective-C相同的类文件中。



我已经咨询了Apple


I have a project that was started in Objective-C, and I am trying to import some Swift code into the same class files that I have previously written Objective-C in.

I have consulted the Apple docs on using Swift and Objective-C in the same project, as well as SO question like this, but still no avail: I continue to get the file not found error after putting in #import "NewTestApp-Swift.h" (NewTestApp is the name of the Product and module).

Here is what I have done so far:

  1. In Define Modules, selected YES for the app.
  2. Ensured that the Product Module name did not have any space in it (see screenshot below question)

I have tried using #import "NewTestApp-Swift.h" inside ViewController.m, ViewController.h and AppDelegate.m but none of them has worked.

What else am I doing incorrectly? Thanks for your help.


Screenshot of settings:


Errors that I am presently encountering:

解决方案

I was running into the same issue and couldn't get my project to import swift into obj-c classes. Using Xcode 6, (should work for Xcode 6+) and was able to do it in this way....

  1. Any class that you need to access in the .h file needs to be a forward declaration like this

@class MySwiftClass;

  1. In the .m file ONLY, if the code is in the same project (module) then you need to import it with

#import "ProductModuleName-Swift.h

Link to the apple documentation about it

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_87

这篇关于将Project-Swift.h导入到Objective-C类...找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆