[英]I need to use a swift class in objective-c and cannot setup my Emilos-Swift.h bridging file to resolve any swift classes in objective-c
Cannot get Xcode to generate the bridging file so it's currently empty and cannot find any guide/docs on what needs to be in the file.无法让 Xcode 生成桥接文件,因此它当前为空,无法找到任何关于文件中需要内容的指南/文档。 The empty bridging file is being imported in the .m where the class is needed.
空桥接文件被导入到需要该类的 .m 文件中。 Swift file using @objcmembers on class definition.
在类定义上使用 @objcmembers 的 Swift 文件。
How and what should go into the bridging file.桥接文件应该如何以及什么内容。 Have looked for two days trying to make this work with no success.
找了两天试图使这项工作没有成功。
Is there a way to turn back on the automatic generation of the bridging file in Xcode?有没有办法在Xcode中重新打开桥接文件的自动生成? Any docs on the contents of the bridging file?
关于桥接文件内容的任何文档?
Don't confuse the two kinds of header.不要混淆这两种标题。 The "bridging header" is for Swift to see Objective-C code.
“桥接头”是让 Swift 看到 Objective-C 代码的。 It isn't relevant here.
这与这里无关。
The way Objective-C sees Swift code is through the generated interface header . Objective-C 看待 Swift 代码的方式是通过生成的接口头文件。 You can see its name in your app target build settings:
您可以在应用程序目标构建设置中看到它的名称:
So what that tells you is that if you #import "MomApp2-Swift.h"
in your .m file, your Objective-C code will see your code that is exposed from Swift.所以这告诉你的是,如果你在你的.m文件中
#import "MomApp2-Swift.h"
,你的 Objective-C 代码将看到你从 Swift 公开的代码。
If you want to see what is in that generated interface header, then after you've done that import, Command-click on the file name.如果你想看到的是在生成接口头,你这样做进口,命令点击该文件名,然后后。
To use a Swift class on objective-c you need to be sure that your class inherits from NSObject
, has an @objc
annotation on class definition and other elements that you want to use need to be marked with @objc
.要在 Objective-c 上使用 Swift 类,您需要确保您的类继承自
NSObject
,在类定义上具有@objc
注释,并且您要使用的其他元素需要用@objc
标记。 @objcmembers
marks all elements visible from an Objc class located on file that imports the "project-Swift.h"
@objcmembers
标记从位于导入"project-Swift.h"
文件上的 Objc 类可见的所有元素
You may not need all class members visible from Objective-c您可能不需要所有从 Objective-c 可见的类成员
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.