Last active
April 14, 2016 19:20
-
-
Save konrad1977/d468f9d493c33eecefac to your computer and use it in GitHub Desktop.
Person with Protocol
This file contains 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
protocol AgeClasificationProtocol { | |
var age: Int { get } | |
func agetype() -> String | |
} | |
class Person { | |
let firstname: String | |
let lastname: String | |
var age: Int | |
init(firstname: String, lastname: String) { | |
self.firstname = firstname | |
self.lastname = lastname | |
self.age = 10 | |
} | |
} | |
extension Person : AgeClasificationProtocol { | |
func fullname() -> String { | |
return firstname + " " + lastname | |
} | |
func agetype() -> String { | |
switch age { | |
case 0...2: | |
return "Baby" | |
case 2...12: | |
return "Child" | |
case 13...19: | |
return "Teenager" | |
case let x where x > 65: | |
return "Elderly" | |
default: | |
return "Normal" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you Natasha. I missed that. I also updated firstName and lastName to constants.