iOS: Beginner’s Guide — UIKit (3/3)

An example of polymorphism
  1. as? (optional downcasting) — The conversion might be or might not be true
  2. as! (forced downcasting) — I am confident that this conversion is true and I am aware that the app will crash if I am wrong
An example of optional downcasting
An example of forced downcasting
An example of forced downcasting
An example of optional downcasting
An example of UIView’s animate method
An example of a trailing closure
An example of a protocol
  1. Both properties of age and name have { get set } attached to them, which means that the conforming types must also make these properties both gettable (readable) and settable (writeable). Also, the conforming type must assign these properties as variables, not constants.
  2. The workingHard() function has no block of code, which indicates that protocols do not provide how these behaviors are being executed, but it is defining how something should behave.
  3. We cannot create instances of a protocol as it isn’t a type, but we can have types (classes or structs) conform to it.
An example of a protocol used in action
An example of an extension
An example of using the mutating keyword
An example of an extension
  1. UInt — an unsigned integer that replaced its capability to hold negative numbers in exchange to hold much larger positive numbers
  2. Int8 — an integer that is consisted of 8 binary digits, holding a maximum value of 127
  3. UInt64 — the largest type of integer that holds up to 18,446,744,073,709,551,615 (18 quintillion and 446 quadrillion…)
  1. self indicates “my current value”
  2. Self indicates “my current data type”
An example of using Self
An example of a protocol extension

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
John Kim

John Kim

75 Followers

iOS Developer | Full Stack Developer | Software Engineer | LinkedIn: john-kim-developer | GitHub: cloudiosx | Portfolio: cloudiosx.com