Swift Basics: Formatting guide


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

Comments

Popular posts from this blog

Setting up a playground

Go to another page