Skip to content

Instantly share code, notes, and snippets.

@tranhieutt
Created July 12, 2017 10:01
Show Gist options
  • Save tranhieutt/80fe1679df323522810b5eb3fa73120c to your computer and use it in GitHub Desktop.
Save tranhieutt/80fe1679df323522810b5eb3fa73120c to your computer and use it in GitHub Desktop.
class Logger {
func printData() {
let cars = [
Car(name: "BWM", color: "Green"),
Car(name: "Toyota", color: "Blue"),
Car(name: "Honda", color: "Black")
]
cars.forEach {cars in
print(cars.printDetails())
}
let bicycles = [
Bicycle(type: "Gongcha"),
Bicycle(type: "DingTea")
]
bicycles.forEach { bicycles in
print(bicycles.printDetails())
}
}
}
class Car {
let name: String
let color: String
init(name: String, color: String) {
self.name = name
self.color = color
}
func printDetails() -> String {
return "My car \(name) with \(color) color"
}
}
class Bicycle {
let type: String
init(type: String) {
self.type = type
}
func printDetails() -> String {
return "My bicycle is \(type)"
}
}
let logger = Logger()
loger.printData()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment