Ios basics-programming specifications

Source: Internet
Author: User

Developing good programming habits is the first prerequisite for starting a new language.


(1) document structure specifications

1. Create a Libs folder to store third-party libraries.

2. Create a Tools Folder to store your own encapsulated class libraries.

3. Create a ViewControllers folder to store all ViewControl

4. Create a Request folder to store network requests

5. Create a Cell folder to store the list items

6. Create related folders such as Images, Music, and Video in the Supporting Files folder to store Images, audios, videos, and other resources respectively.

7. Create the homepage of RootViewController and place it in the underlying directory

8. Create a Constant. h file, store it in the underlying directory, and store constants.

Example:



(2) Naming rules

1. The constant names are all in uppercase and can be separated by underscores (_), for example, MY_LOTTERY_ID.

2. lowercase variable letters, followed by uppercase letters, such as myLotteryId

3. The first letter of the class name is capitalized, for example, @ interface MyLotteryId: NSObject

4. The name must contain a type, such as xxxTv, xxxView, and xxxStr.

Common types are abbreviated as follows:

UIViewController: VC UIImage: Img UIImageView: Iv

UIView: View UILabel: Lbl UIButton: Btn

UINavigationBar: NBar UIToolBar: TBar UISearchBar: SBar

UITextField: Tf UITextView: TV NSArray: Array

NSMutableArray: MArray NSDictionary: Dict NSMutableDictionary: MDict

NSString: Str NSMutableString: MStr NSSet: Set NSMutableSet: MSet

5. Add the s sign before the static variable, such as sLotteryId


For more naming conventions, see the official documentation of apple.


(3) coding habits

1. Briefly describe the role of each file

2. Use # pragma mark in the function module of the class to make remarks for convenient searching and code management.

3. Delete NSLog after testing

4. The variable method name in the program should be marked by the naming function whenever possible. Annotations cannot be used to describe the variables.

5. Load preprocessing and Automatic log removal settings in the pch File

6. The number of lines of the class code should not exceed 300, and a function should not exceed 100. If the number of lines exceeds, consider refactoring.

7. Create a Constant. h file storage Constant

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.