IOS programming Specification

Source: Internet
Author: User

When creating a project, I hope to operate according to this variable specification. When other people look at it, check it, and change your code, I will be aware of it, instead of saying, this silly code is so messy. Very useful. Share it!

Code Specification

I. Document structure management

1. Create the libraries folder and place all third-party libraries in it.

2. Create the utilities folder and put the encapsulated classes in it.

3. Create the constants. h header file, where all constants are defined. The constants. h file is placed in the main file group.

4. Put each functional block into a group and create an actual folder management in the directory.

5. Put the program resource file in the supporting Files folder. Such as. plist and database materials.

6. Create related folders such as image, music, and video in the supporting Files folder. Images, audios, videos, and other resources are included in the list. The image resources are managed by creating corresponding object folders Based on the program logic framework. If multiple functional blocks are shared, create a common folder and put it in it.

Ii. coding specifications: in order not to affect reading, the number of lines of code in a class should not exceed 300; a method should not exceed 30 lines. If there is more than one, try to break it down during refactoring. 1. At the beginning of each. h file, use a short text to describe the functional logic of this class.

2. If you want to introduce other classes as instance variables in. H. Otherwise, it will be introduced in. M.

3. There is a blank line between @ interface and @ implementation and # import. @ Synthesize followed by @ implementation.

4. A: declare all instance variables as attributes.

B: The instance variables and methods to be accessed by other classes are declared in the. h file; otherwise, they are declared in the. M file.

C: The instance variables and methods are put together with function blocks to implement continuous integration of one function, and the declaration starts with a blank line of the other function.

D: The instance variable starts immediately after @ interface, and the method starts with a blank line after the instance variable.

E: each function block can be briefly described. The variable methods of a single instance are not described. The key or special variables or methods are described separately. The comment is placed on the previous line of variable declaration.

5. The first functional module in the class is separated by # pragma mark-. The first line is over the sky and the next line is empty.

6. nslog will be deleted after the test is complete.

7. Add a suffix when declaring instance variables for common classes in the system:

Uiviewcontroller: VC

Uiimage: IMG uiimageview: imgview uiview: View uilabel: LBL

Uibutton: BTN uinavigationbar: nbar uitoolbar: tbar uisearchbar: sbar

Uitextfield: textfield uitextview: textview

Nsarray: array nsmutablearray: marray

Nsdictionary: dict nsmutabledictionary: mdict

Nsstring: Str nsmutablestring: mstr

Nsset: Set nsmutableset: mset

8. The variables and methods in the program should be named literally to express the function. For some codes that need to be interpreted with annotations, the annotations are expressed in the following format:

/**

* Description of methods or variables

* @ Param parameter 1 Description (for methods)

* @ Param parameter 2 Description (for methods)

* @ Return if the method has a return value, the return value is described.

*/

 

Iii. xcode Configuration

1. All uses the arc.

2. Use git to manage code.

3. Add a nslog Code to remove release to the project. PCH file:

# Ifndef _ optimize __

# Define nslog (...) nslog (_ va_args __)

# Else

# Define nslog (...){}

# Endif

From: http://www.cnblogs.com/celestial/archive/2012/06/30/2571417.html

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.