Applying Protocol-Oriented Programming in Development

Oct 17 2023 · Swift 5.9, iOS 17, Xcode 15

Lesson 02: Protocol Design & Composition

Demo 1

Episode complete

Play next episode

Next

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

Demo

Now, it’s time to see how to implement a MediaCollection. Open the starter project playground for this lesson in Xcode. MediaItem and MediaCollection are already defined for you.

struct MovieCollection: MediaCollection {

}
typealias Item = Movie
var items: [Movie] = []
func getDescription() -> String {
    "The movie collection contains \(items.count) movies"
}
let bourneIdentity = Movie(title: "The Bourne Identity", price: 3.99, duration: 113)
let oppenheimer = Movie(title: "Oppenheimer", price: 17.99, duration: 180)

var movieCollection = MovieCollection()
movieCollection.items.append(bourneIdentity)
movieCollection.items.append(oppenheimer)

print(movieCollection.getDescription())
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction 1 Next: Instruction 2