What is the difference between #import <Library / Library.h> and #import <Library.h> using CocoaPods?

I saw CocoaPods tutorials that recommend importing the required POD library header as follows:

#import <Library/Library.h> 

Where Library is the name of the library (for example, #import <AFNetworking/AFNetworking.h> ).

I also saw manuals that recommend importing the required POD library header as follows:

 #import <Library.h> 

(e.g. #import <AFNetworking.h> )

Both methods are compiled and seem to work.

What is the difference and which should be used?

+6
source share
2 answers

In any case, it works fine if the imported header is unique. But if you have a header with the same name in two different third-party libraries, it becomes ambiguous, and you will need to specify which one you want.

As a rule, it is better to indicate the name of the library so that this does not happen, but also because it immediately became clear that someone was reading your code, which library this header file is in, because it does not always appear based on the header name .

+6
source

Actualy:

 #import <Library/Library.h> 

differs from:

 #import <Library.h> 

In the first case, you tell the preprocessor that there is a directory in HEADER_SEARCH_PATH that contains a directory called "Library", and in this directory there is a file "Library.h". In the second case, the preprocessor assumes that it can directly find "Library.h" in HEADER_SEARCH_PATH. If both directories are in HEADER_SEARCH_PATH, there is no difference between the two. Some CocoaPods Indicate in Specifications

  s.header_mappings_dir = 'SomeFolderWhereSourcesPlaced' 

In this case

 A directory from where to preserve the folder structure for the headers files. If not provided the headers files are flattened. 

So, if the name header_mappings_dir is specified, full paths are required because pod install only points to the root directory where it places the headers.

+1
source

All Articles