I have specific coding style for Swift.
-
Follow Apple's Cocoa coding style. (Camel case, uppercases for abbreviations, etc.)
-
Openign braces
{
at same line.func exampleFunction1() -> Int { }
This is specifically because Swift does not support to put
{
at new line for closure syntax. -
Fully descriptive name for any public interfacing elements.
-
You can use shortest name for local (that means will not be referred from another places) variable if their roles are (1)temporary, or (2)obvious and super-clean.
func exampleFunction1() -> Int { let a = 123 let a1 = a + 100 return a1 }
It is too inefficient to figure out formal name for all local variables. Anyway sometimes you need to use formal descriptive names if roles of the variables are not super-obvious.
-
Use tabs to align assignment.
func exampleFunction1() -> Int { let a = 123 let a1 = a + 100 return a1 }
Usually one tab is enough because most variable names are shorter then 4 letters.