0

Edit:

I finally found out that I import a header file which has indirect import for the JSONModel.h file.


Today I tried AppCode and it gives me some hint that some import is useless.

I found out that it seems that some subclasses of [JSONModel][1] can omit import statement of its own header file in the implementation file (.m file) and compile successfully.

For example:

TestModel.h

#import "JSONModel.h"

@interface TestModel : JSONModel

+ (JSONKeyMapper *)keyMapperWithJsonToModelDic:(NSDictionary *)jsonToModelDic;

@end

TestModel.m

@implementation TestModel

+ (JSONKeyMapper *)keyMapperWithJsonToModelDic:(NSDictionary *)jsonToModelDic {
    return jsonToModelDic;
}

@end

So when can I omit the import statement?

Thanks.

xi.lin
  • 3,326
  • 2
  • 31
  • 57

1 Answers1

4

Because of the Prefix header file (ProjectName-Prefix.pch) which contains the necessary system header files and is applied to all implementation files by Xcode.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • You are right about the previous example! But there are other cases that is not handled by the prefix.pch file. Please see my modifications. – xi.lin Dec 30 '15 at 10:30
  • You are brilliant! I finally found out I have other header file which import the header file indirectly. – xi.lin Jan 06 '16 at 08:41