将 Project-Swift.h 导入到 Objective-C 类中...找不到文件 [英] Importing Project-Swift.h into a Objective-C class...file not found
问题描述
我有一个用 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:
- In
Define Modules
, selectedYES
for the app. - 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....
- Any class that you need to access in the .h file needs to be a forward declaration like this
@class MySwiftClass;
- 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
这篇关于将 Project-Swift.h 导入到 Objective-C 类中...找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!