gpt4 book ai didi

objective-c - 在 Objc *.m 文件中编写 Swift 2.0 代码

转载 作者:行者123 更新时间:2023-11-30 13:40:15 25 4
gpt4 key购买 nike

我正在尝试使用 Objective-c .m 文件中的快速类方法,但无法导入文件。

在“build设置”->“打包”中,我有:定义模块是我的产品模块名称在“构建选项”中,我已将嵌入内容包含 Swift 代码设置为

但是,当我尝试将目标模块导入到 *.m 文件时,出现文件未找到错误。

#import "Library-Swift.h"

导入失败。

我有 swift 文件。有任何想法吗?

我还尝试使用“Library-Bridging-Header.h”

//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "PLAddBookViewController.h"

..但它似乎没有做任何事情。

最佳答案

您可以通过两种方式将 Swift 类公开给 ObjC:

class MySwiftClass : NSObject { // inherit from any ObjC class
}

@objc class MyClassClass { // tell the compiler to expose it to ObjC
}

来自Swift book :

When you define a Swift class that inherits from NSObject or any other Objective-C class, the class is automatically compatible with Objective-C. If your Swift class does not derive from an Objective-C class and you want to use an API from that class in Objective-C code, you can use the @objc attribute described below.

The @objc attribute makes your Swift API available in Objective-C and the Objective-C runtime. In other words, you can use the @objc attribute before a Swift method, property, subscript, initializer, class, protocol, or enumeration to use it from Objective-C code.

关于objective-c - 在 Objc *.m 文件中编写 Swift 2.0 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35658513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com