Created
July 12, 2017 10:01
-
-
Save tranhieutt/80fe1679df323522810b5eb3fa73120c 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
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