IOS review notes: Objective-C syntax Basics

Source: Internet
Author: User

IOS review notes: Objective-C syntax Basics

I. Syntax Basics

1 keyword

The keywords basically start with @. Common keywords are as follows:

@ Interface, @ implement, @ end, @ public, @ private, @ selector, @ required, @ encode, etc.

Other IDs, self, super, etc.

 

2. the string starts @.

@ "Hello world! "

 

3 Boolean Yes/No

 

4. null type nil (value: 0)

 

5 other C language syntax

 

2 OC HelloWorld Program

 

// Helloworld. m # import
 
  
# Include
  
   
Int main () {printf ("OC fully compatible with C \ n"); NSLog (@ "Hello World"); // automatically wrap return 0 ;}
  
 

 

 

In Mac, cc is compiled using clang.

Compile:

 

cc -c helloworld.m

 

A hellowold. o will be generated under the current folder.


Link:

 

cc hellowork.o -framework Foundataion
A. out will be generated under the current folder.

 

Run:

 

./a.out

It will be printed on the screen:

 

Fully compatible with C
19:10:49. 451 a. out [503: 507] HelloWorld

 

3-plus files

 

// main.m#import "helloworld.h"int main(){    show();    return 0;}

# Import
 
  
# Include
  
   
// Helloworld. hvoid show () {printf ("OC fully compatible with C \ n"); NSLog (@ "HelloWorld ");}
  
 

Compile and generate the. o file:

 

 

cc -c main.m

Link generation a. out
cc main.o

The running mode and result are the same as above.

 

 

 

 

Related Article

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.