如何将Swift代码导入Objective-C? [英] How can I import Swift code to Objective-C?

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

问题描述

我在Swift中编写了一个库,但我无法将其导入到当前项目中,用Objective-C编写。

I have written a library in Swift and I wasn't able to import it to my current project, written in Objective-C.

有没有办法进口吗?

#import "SCLAlertView.swift" - 'SCLAlertView.swift' file not found


推荐答案

您需要导入 TargetName-Swift.h 。请注意,它是目标名称 - 其他答案错误地使用了类名。

You need to import TargetName-Swift.h. Note that it's the target name - the other answers make the mistake of using the class name.

这个单个文件是一个自动生成的头文件,它定义了所有Swift的Objective-C接口项目中的类,使用 @objc 进行注释,或者从 NSObject 继承。

This single file is an autogenerated header that defines Objective-C interfaces for all Swift classes in your project that are either annotated with @objc or inherit from NSObject.

注意事项:


  • 如果您的目标名称包含空格,请将其替换为下划线(例如我的项目变为 My_Project-Swift.h

如果您的目标是框架,则需要导入< TargetName / TargetName-Swift.h>

If your target is a framework, you need to import <TargetName/TargetName-Swift.h>

这篇关于如何将Swift代码导入Objective-C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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