Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C enum is not visible in Swift

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?

like image 699
BalestraPatrick Avatar asked Dec 24 '22 16:12

BalestraPatrick


1 Answers

I had the same issue and resolved it by doing BOTH of the following:

  1. Move the enum declaration to outside the @interface block
  2. Remove the period '.' from the enum reference in the Swift code

let fontSize:FontSize = VerySmall

like image 87
danfordham Avatar answered Dec 28 '22 08:12

danfordham