OC Language Learning (i) Hello world

Source: Internet
Author: User

. h : Header file. Header files contain declarations of classes, types, functions, and constants.  

. M : source code file. This is a typical source code file extension that can contain objective-c and C code.  

. MM : source code file. 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.

You can use standard #include compilation options when you need to include header files in your source code, but objective-c provides a better approach. The #import option is identical to the #include option, except that it ensures that the same file will only be included once.


#import <Foundation/Foundation.h>

OC recommended with #import contains header files, C-language method of # include can also

Foundation Framework

The include file is the same as C, and the user of the <> system


Key words

@interface,@implementation,@end

@public, @protected,@private,@selector

@try,@catch,@throw,@finally

@protocol,@class

Self, id, super, _cmd, _block, _strong, _weak (does not start with @)

The new keywords introduced in OC 2.0 have

@property,@synthesize

@optional,@required,@dynamic




The program entry is also a main function
The nslog function is defined as the form of C .

is a log output function that outputs incoming OC string parameters to the console

Automatic line wrapping after output is complete

Support for format characters:

*%f means to receive floating-point data,%.2f means to retain 2 decimal places

The format of the NSLog is as follows:

%@

Object

%d,%i

integer

%u,%z

No character shaping

%f

floating point / double word

%x,%x

hexadecimal integer

%o

octal integer

%zu

size_t

%p

pointer

%e

floating / double word (scientific calculation)

%g

floating point / double word

%s

c character String

%.*s

pascal string

%c

character

%c

unichar

%lld

64 bit long integer ( long Long

%llu

no 64 bit long integer

%lf

64 bit double word

%hhd

BOOL Boolean type

NSLog (@ "Hello World");//The string starts with @ in OC
#import <foundation/foundation.h>int Main () {    NSLog (@ "Hello world");    return 0;}



OC Language Learning (i) Hello world

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.