640
Today topic:
- Properties
- Methods
- Advanced Classes Enumerations
- Protocols
- Generics
Exercises:
Exercise 01: PROPERTY
- Show me an example about a struct have property is another struct
- What is type property, example by source code
1 and 1 point
Exercise 02: Methods
- Define struct Coordinate with property have latitude and longitude. Write a method to get/set for this property
- (Optional) Compare between class’s method and struct’s method
1 and 0.5 point
Exercise 03: Advanced class
What is deinit of class?
Create three simple classes called A, B, and C where C inherits from B and B inherits from A.
Write init method that print class name before and after call super.init
Write deinit method then printed simple log like: Destroy A / B / C
Now, look at below codes
do {
let _ = C()
}
These codes will create an instace of C then release. Please explain printed log
2 point
Exercise 04: Protocols
Define a protocol Vehical, this protocol will have some properties like fuel, speed, and some method like run()…
Implement at least 3 class conform to this protocol and show me difference kind of run()
What do you think about inheritance and protocol for this case?
2.5 point