Skip to content

Instantly share code, notes, and snippets.

@NatashaTheRobot
Forked from konrad1977/Person_v4.swift
Created October 26, 2014 19:43
Show Gist options
  • Save NatashaTheRobot/2f0b83b483a49917ea04 to your computer and use it in GitHub Desktop.
Save NatashaTheRobot/2f0b83b483a49917ea04 to your computer and use it in GitHub Desktop.
protocol AgeClasificationProtocol {
var age: Int { get }
func agetype() -> String
}
class Person {
var firstname: String
var 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