在 Objective-C 框架中导入 Swift 类 [英] Importing Swift classes within a Objective-C Framework

查看:84
本文介绍了在 Objective-C 框架中导入 Swift 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义框架,其中包含一堆 Objective-C 类.在框架内,我想使用 Swift 添加更多类.但是,当尝试使用:MyProduct-Swift.h 将 Swift 类公开给 Objective-C 代码时,它显示为找不到MyProduct-Swift.h文件".

I have a custom Framework that has a bunch of Objective-C Classes. Within the Framework, I'd like to add more classes using Swift. However, when trying to expose the Swift classes to the Objective-C code using: MyProduct-Swift.h, it comes up as "MyProduct-Swift.h file not found".

我已经在单个视图模板中尝试过这个,效果很好.框架内不能导入 Swift 吗?

I've tried this in a single view template and it works fine. Is it not possible to import Swift within a framework?

我还验证了我已经设置了定义模块设置和模块名称.无论有没有这些设置,我都试过了.

I've also verified that I have set the Defines Module setting and the Module Name. I've tried it with and without these settings.

推荐答案

我发现了一些额外的步骤来使其全部工作.除了将定义模块"设置为是"和产品模块名称"(如果您在 Xcode 6 中创建新的触摸框架,通常默认设置正确),您还需要:

I found some additional steps to make it all work. In addition to setting 'Define Module' to YES and 'Product Module Name' (usually these are set correct by default if you create new touch Framework in Xcode 6) you also need:

  1. 在 Objective C 中为您需要的所有 Swift 类添加public"关键字
  2. 您甚至需要向要从 Objective C 访问的类中的所有方法和属性添加 'public' 关键字
  3. 您需要像这样以长"的方式导入 Swift 标头:

#import <项目名称/模块名称-Swift.h>

这篇关于在 Objective-C 框架中导入 Swift 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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