gpt4 book ai didi

ios - 导入 Obj-C 文件,该文件导入自动生成的 Swift header

转载 作者:可可西里 更新时间:2023-11-01 01:17:57 25 4
gpt4 key购买 nike

这是 Import a file in bridging-header which imports Swift header 的部分副本但我遇到了与 Rich 相同的问题

But what about enums declared in Swift? :(

我正在将 Obj-C iPad 应用程序移植到 iPhone。但是,我是一名 Swift 开发人员,我真的不想重写现有功能;而是替换 UI。

我为 iPhone 版本创建了一个新目标。在我的桥接 header 中,我导入了一个使用 #import "ProjectName-Swift.h" 的 obj-c 类。由于此文件是自动生成的,因此在我构建此新目标时它不存在。 linked答案是添加一个 @class 但遗留代码使用了一个枚举,它现在给出错误“Expected a type”。

// File that I am currently importing
-(void)setSmileyType:(SmileyFace)type andDelegate:(id<NumberRatingDelegate>)delegate;
// This line now throws an error "Expected a type"

//File that was previously auto imported
@objc public enum SmileyFace: Int {

最佳答案

Swift 中的

@objc enum 在 ProjectName-Swift.h 中公开为 C-enum。(使用宏 SWIFT_ENUM。)

您可以将类似这样的内容放入使用 Swift 枚举的 Objective-C 头文件中:

typedef enum SmileyFace: NSInteger SmileyFace;

(与使用宏 SWIFT_ENUM 生成的代码的第一部分相同。)

关于ios - 导入 Obj-C 文件,该文件导入自动生成的 Swift header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45551785/

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