I have pch-file with this code:
#import "ServerModel.h"
enum {
SAVE = 1,
REMOVE = 2,
REMOVE_ALL = 3
};
typedef NSInteger RequestType;
and I’m trying to use RequestType in ServerModel.h but compiler doesn’t know nothing about my enum. I tried to create header file for my enums and import this file in pch-file but nothing have changed.
So basic problem is: I can’t use enums from .pch file in files, that are #imported in this pch-file.
Is there some way to handle this problem? And is pch-file good place to put enums there?
UPD:
I tried to put all this enums in one header file and #import this file in the end of all #imports in pch-file and it doesn’t work.
But then I put
#import "Enums.h" // my file with enums
in the beginning of pch-file, before all other #imports and it’s working.
I will be glad if somebody will explain the difference in the placement of #import before or after some other #import.
UPD2:
I’ll try to make it more clearly:
I have Enums.h with enum:
enum {
SAVE = 1,
REMOVE = 2,
REMOVE_ALL = 3
};
typedef NSInteger RequestType;
MyProject-Prefix.pch with:
#import "ServerModel.h"
#import "Enum.h"
and ServerModel.h with following code:
- (void)unlinkAccountWithRequestType:(RequestType)requestType;
I’m getting an error: Expected a type on this method. I’ve cleaned my project and getting same error.
When I’m switching #imports like this:
#import "Enums.h"
#import "ServerModel.h"
Everything is good
Case1 : If you import like this
Then compiler will check
ServerModel.hfile beforeEnums.hwhen it encounters#import "ServerModel.h"statement. And while checking youServerModel.hit finds atokenRequestTypeand says WTF is RequestType?? and throws error on your face.Case 2: If you write this
Then compiler compiles
Enums.hsuccessfully and then compilesServerModel.hand again it finds atokenRequestTypeand says yeah I know this is atypedefofNSIntegerwhich is defined inEnums.h. And finally it moves on happily.