导入 Obj-C 文件导入 auto-generated Swift header
Import Obj-C file which imports auto-generated Swift header
这是 but I encounter the same issue as
的部分重复
But what about enums declared in Swift? :(
我正在将 Obj-C iPad 应用移植到 iPhone。然而,我是一名 Swift 开发人员,他真的不想重写现有功能;替换 UI 代替。
我为 iPhone 版本创建了一个新目标。在我的桥接 header 中,我导入了一个使用 #import "ProjectName-Swift.h"
的 obj-c class。由于此文件是自动生成的,因此在我构建此新目标时它不存在。 的答案是添加一个 @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 {
@objc enum
in Swift 在 ProjectName-Swift.h 中作为 C 枚举公开。
(使用宏SWIFT_ENUM
。)
您可以将类似的内容放入使用 Swift 枚举的 Objective-C 头文件中:
typedef enum SmileyFace: NSInteger SmileyFace;
(与使用宏 SWIFT_ENUM
生成的代码的第一部分相同。)
这是
But what about enums declared in Swift? :(
我正在将 Obj-C iPad 应用移植到 iPhone。然而,我是一名 Swift 开发人员,他真的不想重写现有功能;替换 UI 代替。
我为 iPhone 版本创建了一个新目标。在我的桥接 header 中,我导入了一个使用 #import "ProjectName-Swift.h"
的 obj-c class。由于此文件是自动生成的,因此在我构建此新目标时它不存在。 @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 {
@objc enum
in Swift 在 ProjectName-Swift.h 中作为 C 枚举公开。
(使用宏SWIFT_ENUM
。)
您可以将类似的内容放入使用 Swift 枚举的 Objective-C 头文件中:
typedef enum SmileyFace: NSInteger SmileyFace;
(与使用宏 SWIFT_ENUM
生成的代码的第一部分相同。)