Skip to content

Instantly share code, notes, and snippets.

@vvit
Last active September 21, 2017 14:00
Show Gist options
  • Save vvit/f9dff035d1845c596d8ebd7942116ec4 to your computer and use it in GitHub Desktop.
Save vvit/f9dff035d1845c596d8ebd7942116ec4 to your computer and use it in GitHub Desktop.
// Singleton
final class Singleton {
static let shared = Singleton()
private init() { // forbid object creation
}
}
// Lazy
lazy var players = {
return ["A", "B"]
}()
// -OR-
lazy var players = self.initialPlayers()
func initialPlayers() -> [String] {
return ["A", "B"]
}
// Enumeration
let indexAndNum = [7, 8, 9, 10].enumerate().map { (index, element) in
return "\(index): \(element)"
}
// Debug literals
print(#file #line #column #function)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment