"iOS development". H,.m,.mm,.cpp and other differences
File differences:
. h: Header file. Header files contain declarations of classes, types, functions, and constants.
. m: Source code files. This is a typical source code file extension that can contain objective-c and C code.
. MM: Source code files. Source code files with this extension can contain C + + code in addition to the OBJECTIVE-C and C code. This extension is only used when you really need to use C + + classes or features in your objective-c code.
. cpp: Compile C + + only
You can use the standard # include compilation option when you need to include header files in your source code, but Objective-c provides a better approach. The #import选项和 # Include option is exactly the same, except that it ensures that the same file is included only once. Objective-c's examples and documentation tend to use #import.
The difference between. m and. MM is to tell gcc some parameters to add at compile time. Of course. MM can also be named as. m, but manually add parameters at compile time (trouble)
Common scenarios:
If you have a reference or code containing C + + in your OC code, change this class to. mm;
Example:
Error:./zxing/cpp/core/src/zxing/common/counted.h:21:10: ' iostream ' File not found
When referring to zxing, #import used the iostream, but it is the following class/iphoneos6.1/user/include/c++, it is necessary to change the class name to. mm
Note that the location of the #import or # include in the. mm file is useless if it is in the. h header file.
iOS Issues Summary: 2015-1-9 "ios development". H,.m,.mm,.cpp and other differences