Dark Horse programmer 03-second OC Program

Source: Internet
Author: User

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

  1. CC-C main. m
  2. CC main. O-framework Foundation

(The-framework foundation must be added only when the foundation framework is used)

  1. Run./A. Out

3. Differences between nslog and printf

  1. To use nslog, # import <Foundation/Foundation. h>
  2. To use printf, # include <stdio. h>
  3. Nslog receives OC strings as parameters, and printf receives C language strings as parameters.
  4. Nslog will automatically wrap after output, but not after printf output

4. # role of Import

  1. Like # include, it is used to copy the content of a file.
  2. 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.

  1. # Import is an upgraded version of # include. We will use # import later.

5. Role of the foundation framework

 #import <Foundation/Foundation.h>
  1. Develop essential frameworks for OC, IOS, and Mac programs.
  2. This framework contains many common APIs (Application excuses ).
  3. The Framework contains many header files. If you want to use the entire framework, you can include its main header file.
  4. 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

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

  1. C language uses printf function to output content; OC language uses nslog function to output content, and nslog output content will automatically wrap.
  2. There must be no space between @ and "" In the nslog output statement.
  3. -Framework foundation must be added only when the foundation framework is used.
  4. # Import can automatically prevent file content from being copied multiple times and will be used later # import.
  5. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.