IOS Code Specification

Source: Internet
Author: User

Overview

The name of the good or bad in the development often also do not pay much attention, after all, poor naming will not affect the program logic. But the poor naming of the hidden maintenance costs associated with large projects is quite high, which may be difficult to detect at the start of a project, and later fall into fought's maintenance dilemma. We often attach great importance to the complexity of the project logic, but can not be a good "simple" name to do well. In fact, if the simple things are not good, then make more complex things that is rubbish.

Naming conventions

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: Replyviewdelegate

Method naming

The first letter is lowercase and the first letter of each word is capitalized

Method names use verb phrases

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

"What to" is often randomly named as get the beginning of the method. First get is a verb, so it's still "what to do" or "what to do". Then the Get method is not used to return an object, but it can be used for parameters.

-(Xxitem *) Getitematindex: (nsuinteger) Index                  //bad!! nonstandard naming -(Xxitem *) Itematindex: ( Nsuinteger) Index                     //Good, name clear -(void) GetItem: (Xxitem *) Outitem Atindex: (Nsuinteger The index  // comparison conforms to the specification, but the second one is better. 

Parameter naming

The first letter is lowercase and the first letter of each word is capitalized

Name hints for parameters to be added before each parameter

Example:

-(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) Nibbundleornil-(void ) Performseguewithidentifier: (NSString *) identifier sender: (ID) Sender

Object naming

Using a modifier + type

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.