Approximate code I need to write
@objc(OCSomeEnum)
enum SomeEnum: Int {
case c1
case c2
...
}
extension UnitySSPPlacementType { //available in swift only
...
}
I want to use some multiple values from this enum:
@objc(OCSomeClass)
class SomeClass: NSObject {
@objc
init(cases: [SomeEnum]) {
...
}
}
Problem
@objc
conflicts with [SomeEnum]
(it understands SomeEnum
only).
Note: there are similar questions but they are all about how to use swift enum one value inside objc (or vice versa). No one answers how to work with multiple values in boths languages simultaneously.
The only clue I found out:
https://developer.apple.com/documentation/uikit/uiview/1622451-animatewithduration?language=objc https://developer.apple.com/documentation/uikit/uiview/1622451-animate
Swift
: struct AnimationOptions
Objective-C:
typedef enum UIViewAnimationOptions : NSUInteger {
...
} UIViewAnimationOptions;
But how to declare custom Swift
struct which becomes enum in Objective-C
?
Solution
According to @MartinR advice:
@objc
convenience init(cases: Array<Int>) {
let pCases = cases.map { SomeEnum(rawValue: $0)! }
self.init(cases: pTypes)
}
init(cases: [SomeEnum]) { ... }