Original articles, welcome reprint. Reprint Please specify: Dongsheng's Blog
The code is full of its own defined names, and it is important to take a well-qualified name.
There are many naming methods, but the more famous, widely accepted nomenclature is:
- Hungarian naming, generally just named variables, the principle is: variable name = Type prefix + description, such as Bfoo represents a Boolean type variable, Pfoo represents a pointer type variable. Hungarian naming is still controversial, and several of the swift code codes do not use Hungarian nomenclature.
- L hump naming (Camel-case), also known as camel nomenclature, refers to the use of mixed uppercase and lowercase letters to name. The hump name is divided into: small hump method and big hump method.
A) The small hump method is the first word is all lowercase, followed by the first letter of the word capitalization, such as: Myroomcount;
b) The big Hump method is the first word of the initial letter is also capitalized, such as: classroom.
Hump naming is the main naming method of Swift coding specification, the more named content is different, can choose small hump method or big hump method. The following categories illustrate:
- To name classes, structs, enumerations, and protocols, the large hump method, such as Splitviewcontroller, should be used.
- File name, using the big hump method, such as Blockoperation.swift.
- Extension file, sometimes the extension is defined in a separate file, it is named "Original type name + extension" as the extension file name, such as Nsoperation+operations.swift.
- Variables and attributes should be used with small hump methods, such as Studentnumber.
- Constant, using the large hump method, such as Maxstudentnumber.
- Enumeration members, similar to constants, using the large hump method, such as executionfailed.
- Function and method should adopt small hump method, such as Balanceaccount, isbuttonpressed and so on.
Welcome to follow Dongsheng Sina Weibo @tony_ Dongsheng.
Learn about the latest technical articles, books, tutorials and information on the public platform of the smart Jie classroom
?
More Products iOS, Cocos, mobile design courses please pay attention to the official website of Chi Jie Classroom: http://www.zhijieketang.com
Luxgen Classroom Forum Website: http://51work6.com/forum.php
Learn notes from the zero-starting Swift (day 56)--naming convention