# Programming in Swift: Functions & Types

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

## Part 5: Protocols & Inheritance

### Episode complete

Play next episode

Next

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.

#### 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 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
``````