Programming in Swift: Functions & Types

Jan 4 2022 · Swift 5.5, iOS 15, Xcode 13

Part 5: Protocols & Inheritance

44. Challenge: Protocols

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 43. Protocols & Extensions Next episode: 45. Value vs. Reference Types

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 44. Challenge: Protocols

Update Notes: This course was originally recorded in 2019. It has been reviewed and all content and materials updated as of October 2021.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

This is your final challenge for the course. You’ll find instructions in the playground for this part of the course. Pause the video, and give it a try. Then, come back to see my solutions. Good luck!

protocol Shape {

}
  var area: Double { get }
struct Square: Shape {
  let side: Double
  
  var area: Double {
    side * side
  }
}
extension Numeric {
  var squared: Self { self * self }
}
side.squared
struct Triangle: Shape {

}
  let base: Double
  let height: Double
  var area: Double  {
    0.5 * base * height
  }
struct Circle: Shape {

}
  let radius: Double
  var area: Double  {
  
  }
    .pi * radius.squared
let square = Square(side: 4)
let triangle = Triangle(base: 3, height: 5)
let circle = Circle(radius: 2)
let shapes: [Shape] = [square, triangle, circle]
print(shapes.map { $0.area })
extension FloatingPoint {

}
  var isInteger: Bool {
  
  }
    rounded() == self
let double: Double = 5.0
let float: Float = 3.7
double.isInteger
float.isInteger