I have a project with Swift and Objective-C code. In my current project I have the problem that the #import "Project-Swift.h"
file does not refresh if I add new Swift modules.
我有一个关于Swift和Objective-C代码的项目。在我目前的项目中,我遇到了#import项目- swift的问题。如果我添加新的Swift模块,文件不会刷新。
#import "Project-Swift.h" // does not refresh if I add .swift files
So in the Objective-C universe, the swift code is not available. the files exists, but does only contains default #defines
etc. No project related stuff.
因此在Objective-C中,swift代码不可用。文件存在,但只包含默认的#define等。没有项目相关的东西。
Clear Cache, rebuild, delete Derived Data does not help.
清除缓存、重新构建、删除派生数据都没有帮助。
3 个解决方案
#1
3
Solved it. Forgot @objc(<class>)
. It is mandatory.
解决它。忘了@objc( <课程> )。它是强制性的。
Details here (Migrating)
细节(迁移)
Migrating Objective-C Code to Swift
将Objective-C代码迁移到Swift
And here (Swift Type Compatibility)
这里(Swift类型兼容性)
Interacting with Objective-C APIs
与objective - c api交互
#2
1
Just use @objc before Swift Class that you want to use in Object-C code then Build the project. For example:
在Swift类之前使用@objc,您希望在Object-C代码中使用,然后构建项目。例如:
@objc class Person : NSObject
{
// Swfit code goes here.
}
Now #import "Project-Swift.h" will be available in you project to use.
现在# Project-Swift进口”。h"将在你的项目中使用。
#3
1
In my case it worked by building for the other target I had on my project:
在我的案例中,它通过为我的项目的另一个目标而建立:
#1
3
Solved it. Forgot @objc(<class>)
. It is mandatory.
解决它。忘了@objc( <课程> )。它是强制性的。
Details here (Migrating)
细节(迁移)
Migrating Objective-C Code to Swift
将Objective-C代码迁移到Swift
And here (Swift Type Compatibility)
这里(Swift类型兼容性)
Interacting with Objective-C APIs
与objective - c api交互
#2
1
Just use @objc before Swift Class that you want to use in Object-C code then Build the project. For example:
在Swift类之前使用@objc,您希望在Object-C代码中使用,然后构建项目。例如:
@objc class Person : NSObject
{
// Swfit code goes here.
}
Now #import "Project-Swift.h" will be available in you project to use.
现在# Project-Swift进口”。h"将在你的项目中使用。
#3
1
In my case it worked by building for the other target I had on my project:
在我的案例中,它通过为我的项目的另一个目标而建立: