如何将 Swift 代码导入到 Objective

编程入门 行业动态 更新时间:2024-10-26 04:22:10
本文介绍了如何将 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.

有什么办法可以导入吗?

Are there any ways to import it?

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

推荐答案

您需要导入 ProductName-Swift.h.请注意,这是产品名称 - 其他答案错误地使用了类名称.

You need to import ProductName-Swift.h. Note that it's the product 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 变为 My_Project-Swift.h)

如果你的目标是框架,则需要导入

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

确保您的 Swift 文件是目标的成员

Make sure your Swift file is member of the target

更多推荐

如何将 Swift 代码导入到 Objective

本文发布于:2023-08-02 15:24:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1278876.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   导入到   代码   Objective   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!