1

I have one enum which is in constant.h file ( Objective-C )

typedef NS_ENUM (NSInteger, EEFieldType) {
  EEFieldTypeHighFields = 1,
  EEFieldTypeMediumFields = 2,
  EEFieldTypeLowFields = 3
};

I have one bridging file which is connect to swift code and importing one file which file name is profile.

(ModuleName-Bridging-Header.h)

#import "Profile.h" 

profile file using below method which is not compiled in code.

- (EEFieldType)fieldTypeByPFType;

Error : Expected a type on EEFieldType.

Priyank Gandhi
  • 626
  • 2
  • 8
  • 21
  • Can you please reframe your question, its quite confusing to answer. I am not getting what exactly what is the question – Surbhi Garg May 25 '18 at 11:33
  • @SurbhiGarg reframe question might be you will get idea what i am trying to convey. – Priyank Gandhi May 25 '18 at 11:45
  • `Profile.h` references `EEFieldType`, which is defined in `constant.h`, does `Profile.h` import `constant.h`? If not, why not? If yes you need to provide more information for people to be able to help you. – CRD May 25 '18 at 13:47
  • @CRD Yes , Actually "constant.h" i had added in pch file which is globally defined. – Priyank Gandhi May 26 '18 at 05:29
  • So if I follow you correctly `Profile.h` is not importing `constant.h` but instead you are relying on the pre-complied header (`pch`) facility of Xcode for *Objective-C*. There is no Swift equivalent of the `pch` file, and use of `pch` file with Objective-C has been discouraged in favour of modules for some time. Have you tried importing `constant.h` directly in `Profile.h`? – CRD May 26 '18 at 07:57
  • @CRD Not, I tried after you told me.. and it's works perfectly thanks. – Priyank Gandhi May 26 '18 at 11:57

1 Answers1

3

[Answer moved and expanded from comments]

With the additional information on the use of a pre-compiled header file (.pch) added in the comments, your problem comes down to Swift not using .pch files – they are an Objective-C compiler feature.

In Objective.c Profile.h compiles as the header it depends on, constant.h, is imported by the .pch.

In Swift Profile.h produces the missing type error as it does not import constant.h which defines the type.

Simply import constant.h in Profile.h.

Note: Doing this not only works for Swift it continues to work correctly for Objective-C – the .pch feature is a compiler option to speed up header processing and the Objective-C compiler will continue to use it, when it sees the constant.h import in Profile.h it will simple skip it as already imported by the .pch.

CRD
  • 52,522
  • 5
  • 70
  • 86