Swift Basics: Formatting guide
- Do not use semi-colons.
- Do not use () for if else statement - if x < 5 {} instead of if (x<5){}
- Types should always start with a capital letter. They should not have underscore. MyClass
- Functions and methods should be named in camel case.
- Constants and variables should be named in camel case.
- Use the default indentations given.
- Add an extra blank line between functions and methods.
- Use triple /// in block comments for functions.
- Use double // in comments for inline comments.
- Define everything as a constant first, then change it to a variable when you have to change it.
- Only use optional types when necessary.
- Avoid forced unwrapping. Use optional binding instead.
- Use type inference: instead of var a: Int = 1, use var a = 1
- Use shorthand declarations for collections: var myArray: [String] = [] instead of var myArray: Array<String>
- Use switch case instead of multiple if statements.
Comments
Post a Comment