Created
June 13, 2015 02:42
-
-
Save joanmolinas/51be7ecc15a48b2ada66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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