I want to use enum that is visible both in objective C and Swift but not conform to protocol RawRepresentable.
I tried to have an enum of string both visible in Objc and Swift thus I use
typedef NSString *myEnum NS_TYPED_ENUM;
I tried to take advantage of the myEnum(rawValue: ) -> myEnum? function but I found the enumType has automatically conform to
public struct myEnum : Hashable, Equatable, RawRepresentable { public init(rawValue: String) }
My question is how to create enum that is visiable in Objc and Swift but not conform to this protocol? Thanks for all the help!
Above From Xcode 6.4 Release Notes
For this purpose you define the values in Objective-C, you can use the
NS_TYPED_ENUM
macro to import constants in Swift For example: .h file.m file
In Swift, this is imported as a struct as such:
Although the type is not bridged as an enum, it feels very similar to one when using it in Swift code.
You can read more about this technique in the "Interacting with C APIs" of the Using Swift with Cocoa and Objective-C documentation