Closed wnagrodzki closed 6 years ago
I am wondering about some examples when declaring closure variables, the "type is kept on the right side of the assignment operator" rule sometimes results in quite verbose closure headers.
@pwetrifork Which definition do you prefer the most, or maybe you want to provide an example?
let closure1: (Int, Int) -> Int = { $0 + $1 }
let closure2: (Int, Int) -> Int = { (a, b) in
a + b
}
let closure3 = { (a: Int, b: Int) -> Int in
return a + b
}
I like 2 more than 3 and for simple closures, I would never pick 3 over 1. That's why I had reservations about the general "type to the right of assignment" rule.
@pwetrifork Point taken, I added exception from this rule for closures
Looking fine
Do not declare type if compiler is able to infer it.
Keep type on the right hand side of assignment operator (this rule does not apply for closures, declare the type wherever it helps readability).
Declare constants within appropriate type.
Gather IBOutlets in one group above all the other properties and keep them private.