iphone Development: Objective C Code Specification-ios Summary version

Source: Internet
Author: User


One, about the empty line

Empty lines in the A:.h

1. Empty 1 lines between file description and header file inclusions (#import)

2, header file inclusion (#import), if you need to classify the difference between categories, empty 1 lines

3, header file inclusions (#import) and @class empty 2 lines

4, empty line between @interface and @class

5, the header file {}, empty 1 lines Start declaring object members, if you need to classify the difference between categories, empty 1 rows

6,{} Outer Space 1 lines, writing attributes, if you need to classify the difference between categories empty 1 lines

7, empty 1 lines start writing methods, if you need to classify the difference between categories empty 1 lines

8, after the method is complete, empty 1 lines @end

9, if you need to declare protocal, the empty 2 lines continue to write. Usually the protocal is written behind @end, but the declaration is in front of the @interface, and you can write a different file

Empty lines in the B:.M

1. Empty 1 lines between file description and header file inclusions (#import)

2, header file inclusion (#import), if you need to classify the difference between categories, empty 1 lines

3, empty line between @implementation and @synthesize, @synthesize do not use commas (,) if you need to classify differences, 1 rows between categories

4, empty 2 lines between @synthesize and method

5, empty 2 lines between the methods

C: Empty line inside the method

1, the method name is empty after 1 lines start to write

2, the variable declaration requires empty 1 lines, if you need to classify the difference between categories empty 1 lines

3, condition, loop, select statement, end of entire statement, need empty 1 lines

4, empty 1 lines between each function block

5, not empty line before the last counter parenthesis

6, no blank line between comments and code

7, #pragma between Mark and method empty 1 lines

Two, about the space

1,.h protocol <> 1 spaces in front

When a member is declared in a 2,.h, there are at least 1 spaces between the type and the variable. The asterisk (*) is close to the variable, not near the type. (In some habits, all variables can be aligned with *, leaving the middle blank)

3, after the @property there are 1 spaces, () inside, after the comma has 1 spaces, outside the brackets, leave 1 spaces, and then declare the property

4, after the method +,-, and () there are 1 spaces between

5, there are 1 spaces between the return type and *, and 1 spaces between the return type and * in the method parameter

6, multi-parameter method, each parameter is followed by 1 spaces

Three, about Boolean values

1, do not use if (Obj==nil) {}, and if (!obj) {}

2, you can avoid errors by putting the constants in front of the comparison

Do not use if (aintvalue==255) {}, and if (255==aintvalue) {}, to avoid missing a "=" and become an assignment

3, do not use if (Abool==yes) {}, directly with if (Abool) {} or if (!!). Abool) {}

Four, variable attribute names and other

1, as far as possible in the use of the Declaration of variables, to minimize the use of global variables

2, variable name do not use only one letter, as far as possible to indicate the meaning of the variable

3, @synthesize and @dynamic, should be placed at the top of the class implementation, each declaration is a separate line

4, Protocol protocls need to add #pragam marks-to differentiate

5, release should [obj release],obj = nil; Delegate should also be inside the dealloc delegate = nil;

These are some of my summaries. Other references: Http://www.cimgf.com/zds-code-style-guide/Google objective-c style guide:http://wenku.baidu.com/ View/a9b80ecdda38376baf1faedf.html Most authentic is Apple's official: http://developer.apple.com/library/mac/#documentation/cocoa/ Conceptual/codingguidelines/codingguidelines.html

iphone Development: Objective C Code Specification-ios Summary version

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.