Search code examples
objective-cimportimplementationjsonmodel

Why can I import nothing in .m file


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.


Solution

  • 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.