Nº 2 - Ditch the semicolon

Every time you use a semicolon (;) in swift, a tree dies 🙄. Don’t roll your eyes! It’s true.

Don’t use them, they are a thing of the past. They make your code look ugly and nasty.

Look how ugly:

1
2
let lukeSkywalker = JediKnight();
lukeSkywalker.savePrincessLeia();

Now look how beautiful:

1
2
let lukeSkywalker = JediKnight()
lukeSkywalker.savePrincessLeia()

Nice, clean, perfect 😌.

Share Comments

Nº 1 - Closure retain cycle

Avoid calling self inside your closure as much as possible.

1
2
3
let tower = { [weak self] rapunzel in
return self?.knight.save(rapunzel)
}

What if self is nil? I know what you’re thinking. Forget unowned! Just pass a capture list with the properties you need inside the closure.

1
2
3
let tower = { [knight] rapunzel in
return knight.save(rapunzel)
}

And that is how it is done.

Share Comments