How would you include Swift struct / enum in Objective-C?
Scenario: I exposed an Objective-C file in Swift over a .h bridge; so I can run Objective-C through Storyboard from .Swift.
However, I have a global enum and structures declared in the Environment.Swift file that ObjC requires:
enum BarButtonItem:Int {
case cancel = 1
case back
case save
case activate
case upload
case share
}
Enum access in Swift:
@IBAction func navButtonAction(sender: UIBarButtonItem) {
if let buttonItem = BarButtonItem(rawValue: sender.tag) {
switch buttonItem {
case .save:
println("{(3.3)AccessBoundaries} Save.")
default:
println("")
}
}
self.dismissViewControllerAnimated(true, completion: nil)
}
I want to access this (and other datatypes) in an Objective-C file:
- (IBAction)barButtonAction:(UIBarButtonItem *)sender {
BarButtonItem....?
}
Xcode doesn't recognize this.
How can I open the environment data types (or me?) Defined in the .Swift file into an Objective-C file?
... and is it possible to interpret the .Swift structure in Objective-C?
source to share
There are a number of Swift features that cannot be used in Objective-C. I posted an answer to a question the other day that asked something similar. I'll get you back the answer here:
According to Apple Docs in Swift and Objective-C Compatibility:
You have access to anything in a class or protocol marked with the @objc attribute if it is Objective-C compatible. This only excludes Swift features like the ones listed here:
- Generics
- tuples
- Swift-defined enums
- Structures defined in Swift
- Top-level functions defined in Swift
- Global variables defined in Swift
- Swift-defined typings
- Swift style options
- Nested types
- Functions performed
source to share