Not sure if the right place to ask this, but someone may have a clue.
Scenario: Working on an old Objc Framework, trying to slowly move to Swift.
The problem: I have a swift enum that is used as an objc class property.
This property is not available back in Swift.
@objc enum MyEnum {
case option
}
ObjcClass.h
//I need a forward declaration in there
//because I cant import Project-Swift.h in here, it breaks compilation
typedef NS_ENUM(NSInteger, MyEnum);
@interface ObjcClass
@propert (nonatomic) MyEnum someInfo;
@end
class SwiftLogic {
let obj : SomeObjc
func doThings() {
if obj.info == .option { //Value of type 'SomeObjc' has no member 'info'
}
}
You should probably just declare that enum in Objective-C and import it into Swift, rather than the other way around. Move it back into Swift only after you have turned all of the APIs that visibly use it into Swift APIs. (If the case names don't import the way you'd prefer, remember that you can use NS_SWIFT_NAME to rename them.)
As a general rule, mixed-language targets usually have to declare everything used by a handwritten ObjC header in a handwritten ObjC header. That's kind of just the nature of the beast. C family languages care about the order in which entities are declared, and while Swift can reorder entities in its -Swift.h header to respect that rule, it cannot insert the entities in that header between entities in handwritten headers—it can only insert the whole -Swift.h header after all of the handwritten headers.
That was my first attempt. But when I use enum from Objc into swift, the *-swift.h gets a reference to the framework itself (#import <MyFramework/MyFramework.h>) and this causes all kind of problems for user using cocoapod and static linking.