Objective-C enum not showing up in Swift
I have an enum like this in my objective-c header file:
typedef NS_ENUM(NSInteger, FontSize) {
VerySmall = 12,
Small = 14,
Medium = 16,
Big = 18
};
Then in my bridge header, I import that header.
from my swift code, when I try to declare "FontSize" as a parameter, the compiler says "Use undeclared font FontSize".
From the developer guide, this should be possible. Is anyone experiencing the same problem?
source to share
Start with a clean Swift project , add one file .h
(Accept automatic generation of bridge headers)
Objective-C FontSize.h
typedef NS_ENUM(NSInteger, FontSize) {
VerySmall = 12,
Small = 14,
Medium = 16,
Big = 18
};
Bridging header
#import "FontSize.h"
Fast implementation
import UIKit
class ViewController: UIViewController {
let fontSize:FontSize = .VerySmall
}
Built, linked, launched and tested on Xcode 6.4 and 7.0.
source to share
I still couldn't see my enums even with NS_ENUM's answer above.
It turns out there were changes in XCode 7.3 where NS_ENUM must be defined outside of the @ interface- @end block.
Call obj-c enum from swift work without upgrading to Xcode 7.3 swift 2.2
source to share