[英]forward declare swift enumeration in objective c
I have a swift library that is used by a project with both objective-c and swift.我有一个 swift 库,该库由具有 objective-c 和 swift 的项目使用。
When using a class from the swift library in an objective-c header file, I can just forward declare the swift class, like this: When using a class from the swift library in an objective-c header file, I can just forward declare the swift class, like this:
//SomeViewClass.h
#import <UIKit/UIKit.h>
//forward declaration of the swift class
@class SwiftClass
@interface SomeViewClass : UIView
@property (nonatomic, strong) SwiftClass *swiftInstance;
@end
How to do the same for an enumeration declared in the swift libary?如何对 swift 库中声明的枚举执行相同操作? Let's say i have this swift enumeration:
假设我有这个 swift 枚举:
@objc public enum DtoMusicSelectionType: Int, RawRepresentable, Codable {
case MusicChannel, Calendar
public typealias RawValue = String
public var rawValue: RawValue {
switch self {
case .MusicChannel:
return "MusicChannel"
case .Calendar:
return "Calendar"
}
}
public init?(rawValue: RawValue) {
switch rawValue {
case "MusicChannel":
self = .MusicChannel
case "Calendar":
self = .Calendar
default:
return nil
}
}
}
How can I use that in the SomeViewClass.h?如何在 SomeViewClass.h 中使用它? I want to do something like:
我想做类似的事情:
//SomeViewClass.h
#import <UIKit/UIKit.h>
//forward declaration of the swift class
@class SwiftClass
//How to forward declare an enum???
@enum DtoMusicSelectionType //this does not work
@interface SomeViewClass : UIView
@property (nonatomic) DtoMusicSelectionType musicSelectionType;
@property (nonatomic, strong) SwiftClass *swiftInstance;
@end
You can forward declare with typedef NS_ENUM without a body, like:您可以在没有正文的情况下使用 typedef NS_ENUM 转发声明,例如:
typedef NS_ENUM(NSInteger, DtoMusicSelectionType);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.