iOS Programming specification

Source: Internet
Author: User
Tags notification center

I. Document Structure Management

1. Create a libraries folder where all third-party libraries are placed.

2. Create the Utilities folder, and put the self-encapsulated class into it.

3. Create a Constants.h header file, where all constants are defined. The Constants.h file is placed inside the main filegroup.

4. Each function block is put into a group to establish the actual folder management in the directory.

5. The program resource file is placed in the supporting Files folder. such as. plist, database data, etc.

6. Create an image, music, video and other related folders under the supporting Files folder. Images, audio, video, and other resources are placed in them. Picture resources to the program logical framework to establish the corresponding Entity folder management, if more than one function block shared, set up the common folder, put into it.

second, coding specificationsNote: In order not to affect reading, the code lines of a class should not exceed 300 lines; One method should try not to exceed 30 rows. There are more than one way to break down when refactoring.  1. At the beginning of each. h file, describe the functional logic of the class in short text.

2. When introducing other classes, to be introduced as instance variables in. h. Otherwise, it is introduced in. M.

[email protected] An empty line between @implementation and #import. @synthesize immediately after @implementation wrote.

4.A: Declaring instance variables are declared as attributes.

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

C: Instance variables and methods are put together with function blocks to implement a function that is put together consecutively, and the other function's empty line begins to declare.

D: the instance variable starts immediately after @interface, and the method begins with an empty line after the instance variable.

E: each function block can be simply explained, the single instance variable method can not be described, the key or special variables or methods are described separately. Note is released on a row of the variable declaration.

5. The first function module in the class is separated by #pragma mark-two lines above, and an empty line.

6.NSLog is removed after the test is complete.

7. The variables, method names in the program as far as possible literal meaning function, for the need to use comments to explain the part of the code, comments are expressed in the following format:

/**

* Method or Variable description

* @param parameter 1 description (for method)

* @param parameter 2 description (for method)

* @return The return value is described if the method has a return value

*/

Or
Short description statement (before or after a method)

8. The first letter of the class name, the method of the first letter lowercase, the method of the first letter lowercase, while trying to make the name of the method read like a sentence, to convey the meaning of the method, and not prefixed with the "get" variable name lowercase letter beginning constant with lowercase letter k, followed by the first letter uppercase
9. Write delegate when the type should be weak weak reference, in order to avoid circular reference, when the delegate object does not exist, we write the delegate there is no meaning of the natural need to destroy
10. Instance variable declaration when the variable name is preceded by an underscore "_", the local variable is not added.

11. Notification Center registration needs to dealloc in the corresponding Remove object, an object delegate object to be in the dealloc in time to be nil.

12. Mobile side encountered a common sense problem c = A/b; Without making any judgments about the appearance of this statement, what if B should be 0? Yes, so it must be if (b) {c= A/b}.

13. When you generally judge bool, for example: bool A = [Object action]; Do not direct if (a = = YES) to judge Direct if (a)

Three, Xcode configuration

1. All unified with arc.

2. Manage the code with cornerstone.

3. Add a section of the NSLog code that removes the release from the project. pch File:

#ifndef __optimize__

#define NSLOG (...) NSLog (__va_args__)

#else

#define NSLOG (...) {}

#endif

To write these first, we need to be responsible for the project and our ability to put forward and the habit of responsibility, for our future development is beneficial.

iOS Programming specification

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.