Programming in Swift: Functions & Types

Jan 4 2022 Swift 5.5, iOS 15, Xcode 13

Part 5: Protocols & Inheritance

44. Challenge: Protocols

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See versions

See course reviews

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

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've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

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