Skip to content

Instantly share code, notes, and snippets.

@irpainel-zz
Last active September 2, 2016 19:26
Show Gist options
  • Save irpainel-zz/89b410fb59387204d9853d44dbf9e0b0 to your computer and use it in GitHub Desktop.
Save irpainel-zz/89b410fb59387204d9853d44dbf9e0b0 to your computer and use it in GitHub Desktop.
Swift Cheatsheet
//overriding delegates
private var delegate: SubclassDelegate?
override var superclassDelegate: SuperclassDelegate? {
didSet {
delegate = superclassDelegate as? SubclassDelegate
}
}
//Testing types with switch http://stackoverflow.com/a/25724652/3191130
for thing in things {
switch thing {
case 0 as Int:
println("zero as an Int")
case 0 as Double:
println("zero as a Double")
case let someInt as Int:
println("an integer value of \(someInt)")
case let someDouble as Double where someDouble > 0:
println("a positive double value of \(someDouble)")
case is Double:
println("some other double value that I don't want to print")
case let someString as String:
println("a string value of \"\(someString)\"")
case let (x, y) as (Double, Double):
println("an (x, y) point at \(x), \(y)")
case let movie as Movie:
println("a movie called '\(movie.name)', dir. \(movie.director)")
default:
println("something else")
}
}
//Making init unavailable
@available(*, unavailable)
override init(tableView: UITableView) {
fatalError()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment