Reputation: 10144
I have an enum which is like this declared in my objective-c header file:
typedef NS_ENUM(NSInteger, FontSize) {
VerySmall = 12,
Small = 14,
Medium = 16,
Big = 18
};
Then in my bridging header I import this header.
from my swift code, when I try to declare 'FontSize' as parameter, the compiler says 'Use of undeclared type FontSize'.
From the developer guide, this should be possible. Anyone experiencing the same problem?
Upvotes: 4
Views: 3056
Reputation: 978
I had the same issue and resolved it by doing BOTH of the following:
let fontSize:FontSize = VerySmall
Upvotes: 5
Reputation: 6601
I still couldn't see my enums even with NS_ENUM answer above.
It turns out there was a change in XCode 7.3 where NS_ENUMs have to be defined outside the @interface-@end block.
Calling obj-c enum from swift not working after upgrading to Xcode 7.3 swift 2.2
Upvotes: 1
Reputation: 48514
Start over with a clean Swift project, add a single .h
file (accept the automatic creation of Bridging-Headers)
Objective-C FontSize.h
typedef NS_ENUM(NSInteger, FontSize) {
VerySmall = 12,
Small = 14,
Medium = 16,
Big = 18
};
Bridging-Header
#import "FontSize.h"
Swift Implementation
import UIKit
class ViewController: UIViewController {
let fontSize:FontSize = .VerySmall
}
Built, linked, ran & tested on Xcode 6.4 & 7.0.
Upvotes: 4