--- Java training, Android training, IOS training, and. Net training. We look forward to communicating with you! ---
1. Code Writing
The second OC program is as follows:
1 # import <Foundation/Foundation. h> 2 3 int main () 4 {5 // nslog output content will automatically wrap 6 // nsl3 letters are all uppercase 7 // No space between @ and "" 8 nslog (@ "2nd OC programs! !! "); 9 10 return 0; 11}
2. Terminal commands
- CC-C main. m
- CC main. O-framework Foundation
(The-framework foundation must be added only when the foundation framework is used)
- Run./A. Out
3. Differences between nslog and printf
- To use nslog, # import <Foundation/Foundation. h>
- To use printf, # include <stdio. h>
- Nslog receives OC strings as parameters, and printf receives C language strings as parameters.
- Nslog will automatically wrap after output, but not after printf output
4. # role of Import
- Like # include, it is used to copy the content of a file.
- It can automatically prevent the file content from being copied multiple times, which means that the following preprocessing commands are not added to the header file.
# Ifndef _ stdio_h _
# DEFINE _ stdio_h _
# Endif
// Nsobjcruntime. h contains the nslog function declaration
# Import <Foundation/nsobjcruntime. h>
<> In/, the previous part indicates the framework name, and the later part indicates the. h header file in the framework.
- # Import is an upgraded version of # include. We will use # import later.
5. Role of the foundation framework
#import <Foundation/Foundation.h>
- Develop essential frameworks for OC, IOS, and Mac programs.
- This framework contains many common APIs (Application excuses ).
- The Framework contains many header files. If you want to use the entire framework, you can include its main header file.
- Storage path of the foundationl framework:
- Right-click xcode. app --> display Package content
- /Applications/xcode. APP/contents/developer/platforms/iphoneos. Platform/Developer
/Sdks/iphoneos. SDK/system/library/frameworks/Foundation. Framework/Headers
- Master header file
- Main header file: The main header file, which is generally the same as the framework name and contains all other header files in the framework.
- The header file name of the foundation framework is foundation. h.
- You only need to include the main header file of the foundation framework to use the entire framework.
Note: Do not add or delete anything.
This section focuses on
- C language uses printf function to output content; OC language uses nslog function to output content, and nslog output content will automatically wrap.
- There must be no space between @ and "" In the nslog output statement.
- -Framework foundation must be added only when the foundation framework is used.
- # Import can automatically prevent file content from being copied multiple times and will be used later # import.
- You only need to include the primary header file of the foundation framework to use the entire framework.
Dark Horse programmer 03-second OC Program