I. OC Foundation

Source: Internet
Author: User

How to build an OC client program

1. The first program of OC

2. Data type of OC

3. Written specifications of OC

4. Format characters for OC

1. How do I build a OC client program?

Open Xcode and select Create a new Xcode project

On the left, click the OS X->command line tool control tools

ProductName: Project Name

OrganizationName: Organization Name

Organization Identifier: Organization logo (usually the company domain name upside down)

Language: Using the development language (here we use obejct-c)

Object-c the explanations that appear in the code below

For # include, #import有效处理重复导入问题, no processing in OC, #import自动进行重复处理; similar to # include, import the System class library with <>, import the custom class library with "";

Foundation.h is the header file in the foundation framework, is a basic class library of OC, all the basic OC code should introduce this kind of library;

@autoreleasepool is the key word of OC, which is the function of automatic memory recovery of the program after the keyword;

NSLog is a standard output function, similar to the printf () function in C, which wraps itself, and is declared in Fundation.h;

@ "hello,world!" is a string constant that requires the @ symbol before the string in OC;

Extension:--OJBC syntax features

There is no namespace (C #) or package (Java) concept in OC, the same application cannot have two identical class names at the same time, the prefix is distinguished, for example, in OC NSString, NS in NSLog is the prefix.

Many of the keywords in OC begin with @ (for example, @autoreleasepool, @interface, @protocol), and it is important to note that in order to differentiate the strings in the C language, the strings in OC must also be prefixed with @.

Data type of 2.OC

The basic data types in OBJC are in addition to char, int, float, and double in the C language:

type bool, containing two values Yes and no, in fact the Boolean type in OBJC is the integers 1 and 0;

The ID type, which is an object type that can represent all objects;

Nsintege is essentially a long type

CGFloat is essentially a double type

SEL Method Selector

IMP function pointer

Class type

NSString is a string type defined in the Fundation framework.

Writing specifications for 3.oc

The name of the variable requires the name

The naming of variables and methods is subject to camel hump (except for the first lowercase letter, the other initials need to be capitalized)

Add a comment before each method

Single-line comment, the line that is commented on, will not be run

/**/Multi-line comments, annotated so the content, will not be shipped sex

Before a large classification method, add an index

#prama Mark Index Content

After the index is added, you can click on the direction to view, add the index, click will automatically jump to the location

4. Format characters for OC

With regard to%@, any class has a description method that returns data of a string type. So every time you use%@, this method is called, showing the description of the class.

I. OC Foundation

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.