When reading through the sheet for the first time, one recognizes some minor issues that, if fixed, would increase the value of the sheet without adding substantial weight:
1. String concatenation
Swift has a few basic math operators:
a + b for addition (works for strings too)
The little "works for strings too" is easily overlooked. String concatenation is so fundamental that is should be included into the String section examples.
2. Lazy computed property
lazy var articles:String = {
return Database.getArticles()
}()
The trailing parentheses are unintuitive. What are they for? When and how often is the evaluation being performed?
3. Underscore
func startWorking(_ time:String, withWorkers workers:Int)
The underscore is not found in other languages. What is it used for and why?
4. Enums in switch
let weather = ...
switch weather
{
case .rain:
print("Bring a raincoat!")
The leading dot in ".rain" seems to indicate some kind of scope. What does it mean?
5. Loop basics
The Loops-Section should at least mention continue
and break
and repeat ... while
.
6. Closure syntax
let authenticate = { (name: String, userLevel: Int) -> Bool in
return (name == "Bob" || name == "Alice") && userLevel > 3
}
The syntax of the Closure should be explained with some additional words since it differs from what other languages do.
7. Enum syntax with values
enum Item {
case weapon(Int, Int)
case food(Int)
case armor(Int, Int, Double)
}
This example for an enum does not make sense without further explanation.
8. Comments
The whole section looks like a discussion of personal taste and style, not like a discussion of the language. If there are some strict recommendations from the language authors, this should be pointed out. Otherwise this section should be shortened.
9. Final remarks
I've been looking for a while for a simple document highlighting the essentials for getting started with Swift for people who have long experience with multiple languages. Your cheat sheet is exactly that and I have not yet found anything better. Thanks for the good work.