IOS Naming conventions

Source: Internet
Author: User

 

Ext.: http://blog.csdn.net/zhaoxy_thu/article/details/9090963

 Naming Conventionsclass naming

L capitalize the first letter , then the first letter of each word is capitalized

L use noun phrases that reflect the function of the class

L file and class have the same name

L Example: Baseclient, Imagestore

Special class naming

L If the subclass of the view controller should add the suffix "viewcontroller" or "controller"

L If the subclass of the view should be added suffix "view"

L IF the sub-class of the button should add the suffix "button"

......

L Example: Settingsviewcontroller, Navigationview

Classification (category) naming

L the same name as the class, and add the class name and the "+" to be extended

L Example: nsstring+urlencoding

Protocol (delegate) naming

L Same as Class name, plus add "Delegate" suffix

L Example: replyviewdelegate

method Naming

L First letter lowercase, followed by the first letter of each word is capitalized

L method names use verb phrases

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

method parameter naming

L First letter lowercase, followed by the first letter of each word is capitalized

l have sufficient explanatory

L do not need to add type prefixes

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

variable naming

L First letter lowercase, followed by the first letter of each word is capitalized

L have sufficient explanatory

L member variable does not need to add "_m" prefix

L Member Variable Add "_" prefix

Constants

L constant (pre-defined, local constant, etc.) Camel hump method with lowercase k

L Example: Kinvalidhandle, Kwriteperm

L The enumeration type is capitalized, followed by the first letter of each word, and the last "s"

L Enumeration variables use enum type to remove "s" as prefix , each word capitalized, the middle is not allowed to underline

L Example:

typedef enum uicontrolevents{

Uicontroleventtouchdown,

UIControlEventTouchUpInside

}uicontrolevents;

picture naming

L use English , capitalize the first letter, then capitalize the first letter of each word

L Add module name as prefix to avoid conflict

L pictures should be grouped by module, as with class files

Group naming

L use English , capitalize the first letter, then capitalize the first letter of each word

L Use the name of the module for each grouping

L Use the Open Source Library unified under the "library" sub-group

The common components used are uniformly placed under the "Common" group

L View Controller and Appdelegate unified under the "Controllers" sub-group

Writing SpecificationsNotes

L files contain file headers, which indicate file name, author, creation time, change record

When multiple people collaborate on projects, each method of the public interface should add comments about functions, parameters, return values, and side effects

L when the judgment condition of the IF statement is complex, it is necessary to use the annotation to explain the content

L Interface Class (inherits from Baseclient) header file each method should indicate the function of the method before

Method

L 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

If there are too many parameters, one row per parameter is recommended. With multiple lines, use a colon before the parameter to align, such as:

P-(void) Dosomethingwith: (Gtmfoo *) Thefoo

Rect: (nsrect) Therect

Interval: (float) theinterval

Other Specifications

The l operator is preceded by a space

L Avoid the same code snippet appearing in multiple places

L statement nesting level must not exceed 3 layers

• 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

L Delete or comment out useless code in time

L UITableViewCell the network client inside.

I need to toggle the button after clicking the button picture, when the two pictures are not associated (for example, a picture has a check effect compared to another picture), should not be set to uicontrolselected

L Control Layout uses relative coordinates

L Determine that unused code should be removed

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.