Swift桥接标题和Obj-C类的可见性 [英] Swift Bridging Header and visibility of Obj-C class

查看:168
本文介绍了Swift桥接标题和Obj-C类的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经增加了桥接头,在构建设置中指定了它的完整路径,桥接头是自动创建的.之后,我将obj-c头文件包含在其中.但是,每次调用对象构造函数的尝试都会失败:使用未声明的标识符".

I've aded bridging header, specified in build settings the full path to it, bridging header was created automatically. After this, i've included my obj-c header files in it. But every attempt of calling constructor of object fails : "Use of undeclared identifier".

我已经完成的事情清单:

The list of things i've done :

  1. 创建了.m文件,并建议使用Xcode创建桥接标头
  2. 将obj-c文件添加到项目中并将其导入标头中
  3. 在构建设置中提供了桥接头文件的完整路径

  1. 在代码中使用了Obj-C类型...但是它没有构建.
  2. 然后,我提供的不是标题的完整路径,而是项目所在文件夹的路径-没有结果.

我根据Apple文档仔细检查了所有步骤,但没有结果. 为什么?任何帮助将不胜感激.

I double-checked all the steps according to apple documentation, but no result. Why? Any help would be appreciated.

推荐答案

请按照以下步骤操作:

  1. 创建一个Swift项目
  2. 添加测试类作为可可类,而不是分别添加.m和.h. Xcode提示添加桥接标头.
  3. 将测试类头导入桥接头中,您已经这样做了.在Swift中实例化测试类应该没有问题.
  4. 将BL_KeyChainWrapper .m和.h复制到finder中的项目目录中.
  5. 拖动BL_KeyChainWrapper文件进行投影,并确保添加到目标.
  6. 在桥接头中导入BL_KeyChainWrapper头.
  7. 在Swift中实例化BL_KeyChainWrapper类.
  1. Create a Swift project
  2. Add a test class as Cocoa Class instead of .m and .h separately. Xcode prompt add bridging header.
  3. Import test class header in bridging header, which you already did. Should have no issue instantiate test class in Swift.
  4. Copy BL_KeyChainWrapper .m and .h to project directory in finder.
  5. Drag BL_KeyChainWrapper files to project and make sure Add to Targets.
  6. Import BL_KeyChainWrapper header in bridging header.
  7. Instantiate BL_KeyChainWrapper class in Swift.

如果按照上述步骤进行操作,仍然出现错误.可能您没有在BL_KeyChainWrapper.h中声明名为 BL_KeyChainWrapper 的类.确保在您的BL_KeyChainWrapper.h中,您具有类似以下的代码:

If followed the above steps, and still have the error. It is probably that you didn't declare a class named BL_KeyChainWrapper in BL_KeyChainWrapper.h. Make sure in your BL_KeyChainWrapper.h, you have code like following:

@interface BL_KeyChainWrapper : BaseClass

这篇关于Swift桥接标题和Obj-C类的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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