Given that there is an ObjC compatible enum written in Swift:
// from MessageType.swift
@objc enum MessageType: Int {
case one
case two
}
and an ObjC class with a property of type MessageType
which has to be forwardly declared:
// from Message.h
typedef NS_ENUM(NSInteger, MessageType);
@interface Message: NSObject
@property (nonatomic, readonly) MessageType messageType;
@end
In order to use the Message
in the rest of the Swift codebase, the Message.h
was added into the bridging header:
// from App-Bridging-Header.h
#import "Message.h"
Now, imagine there is a Swift class that tries to read the messageType
property:
// from MessageTypeReader.swift
class MessageTypeReader {
static func readMessageType(of message: Message) -> MessageType {
return message.messageType
}
}
The compilation would fail with the following error:
Value of type 'Message' has no member 'messageType'
My question would be: Is there a way to forwardly declare a Swift enum in order for the MessageTypeReader
to be able to access the property?
Note: I am aware of the possibility of rewriting the Message into Swift or importing App-Bridging-Header.h into Message.h, but that is not an option here, I am looking for a solution that would work with the current setup.
.swift
and.objc
for each enum, perhaps I should have been even more specific in the question. – Ebeneser