Skip to content

Instantly share code, notes, and snippets.

@joanmolinas
Created June 13, 2015 02:42
Show Gist options
  • Save joanmolinas/51be7ecc15a48b2ada66 to your computer and use it in GitHub Desktop.
Save joanmolinas/51be7ecc15a48b2ada66 to your computer and use it in GitHub Desktop.
//New Feature on Swift2
//: # Swift2 Features - Extension Protocol
import Darwin
protocol PrintDescription {
func printDescription() -> String
}
class Person : PrintDescription{
var name = "Joan"
var age = 21
func printDescription() -> String {
return "\(name) - \(age)"
}
}
class Thing : PrintDescription {
var name = "Ball"
var size = 10
func printDescription() -> String {
return "\(name) - \(size)"
}
}
extension PrintDescription {
var awesomenessIndex: String {
get {
return printDescription() + " other description"
}
}
}
var t = Thing()
t.awesomenessIndex
t.printDescription()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment