iOS Code specification

Source: Internet
Author: User

Naming specification class naming
    1. Capitalize the first letter, then capitalize the first letter of each word
    2. Use a noun phrase that reflects the function of the class
    3. File and class have the same name
Special class naming
    1. If the subclass of the view controller should be added with the suffix "viewcontroller" or "Controller", add "Board_iphone" in Beeframwork. Beeuiboard in Beeframework inherits from "Viewcontroller".
    2. If the subclass of the view should be added suffix "view"
    3. If it is a child of the button, the suffix "button" should be added
Classification (category) naming

Same as the class name, plus the class name to extend and the "+"

Example: nsstring+urlencoding

Protocol (delegate) naming

Same as class naming, plus add "Delegate" suffix

Example: Myviewdelegate

Method naming
    1. The first letter is lowercase and the first letter of each word is capitalized
    2. Method names use verb phrases

Example:-(void) Setpostvalue: (int) value

Method parameter naming
    1. The first letter is lowercase and the first letter of each word is capitalized
    2. have sufficient explanatory
    3. No need to add type prefixes

Example:-(void) Senduserinfo: (Nsdictionary *) userInfo

Variable naming
    1. The first letter is lowercase and the first letter of each word is capitalized
    2. have sufficient explanatory
    3. Member variable does not need to add "_m" prefix
    4. Member variable Add "_" prefix
Constant naming
    1. Constant (predefined, local constant, etc.) using a camel-like hump method with lowercase k, for example: Kinvalidhandle, Kwriteperm
    2. The enumeration type is named with the first letter capitalized, followed by the first letter of each word, and the last "s"
    3. Enumeration variables use enum type to remove "s" as prefix, each word capitalized, and no underline is allowed in the middle
      Example:
typedef enum UIControlEvents{UIControlEventTouchDown,UIControlEventTouchUpInside}UIControlEvents;
Picture naming
    1. Use English, capitalize the first letter, and then capitalize the first letter of each word
    2. Add a module name as a prefix to avoid collisions
    3. The picture should be grouped by module, just like the class file
Group naming
    1. Use English, capitalize the first letter, and then capitalize the first letter of each word
    2. Each grouping uses the name of the module
    3. Use the Open Source Library to be unified under the "library" sub-group
    4. Common components used uniformly placed under the "Common" group
    5. View Controller and Appdelegate unified under the "Controllers" sub-group
Writing specification Notes
    1. file contains the file header, to describe the file name, author, creation time, change record
    2. When multiple people collaborate on a project, each method of the public interface should add comments about functions, parameters, return values, and side effects
    3. When the judgment condition of the IF statement is complex, it is necessary to judge the content with the comment description
    4. Header files for interface classes (inherited from Baseclient) Each method should indicate the function of the method before
Method
    1. Leave a space between-or + and the return type, but do not leave the interval between the parameters in the parameter list, and each colon must have a descriptive word for the argument, such as: P-(void) dosomethingwithstring: (NSString *) string number: ( int) num
    2. If there are too many parameters, one row is recommended for each parameter. With multiple lines, use a colon before the parameter to align, such as:
-(void)doSomethingWith:(GTMFoo *)theFoo rect:(NSRect)theRect interval:(float)theInterval
Other specifications
    1. Add spaces before and after operators
    2. Avoid the same code snippet appearing in multiple places
    3. Statement nesting level must not exceed 3 layers
    4. Each implementation file is recommended to be within 500 lines, not more than 1000 rows, and should be considered after the code is refactored through an abstract class
    5. Delete or comment out useless code in time
    6. The network client inside the UITableViewCell must be commissioned.
    7. After clicking the button, you need to toggle the button picture, when the two pictures are not associated (for example, one picture has a check effect compared to another picture), should not be set to uicontrolselected
    8. Control layout uses relative coordinates
    9. Determine that unused code should be removed

iOS Code 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.