Fresher Training—iOS Swift Day 2

by NhatHM

Today topic:

  • Properties
  • Methods
  • Advanced Classes Enumerations
  • Protocols
  • Generics


Exercise 01: PROPERTY
  1. Show me an example about a struct have property is another struct
  2. What is type property, example by source code

1 and 1 point

Exercise 02: Methods
  1. Define struct Coordinate with property have latitude and longitude. Write a method to get/set for this property
  2. (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

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.