Applying Protocol-Oriented Programming in Development

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

Lesson 03: Protocols & SwiftUI

Demo 2

Episode complete

Play next episode

Next

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

POP Demo

Head back to Xcode, where you’ll see how to use POP for the media shelf.

protocol MediaRepository {
    associatedtype Item: MediaItem & Identifiable & View
    
    func getItems() async throws -> [Item]
}
struct VideoGameMediaRepository: MediaRepository {
    func getItems() async throws -> [VideoGame] {
        [arkhamKnight, tearsOfTheKingdom].shuffled()
    }
}
let repository: any MediaRepository
@State var items: [T] = []
let view = MediaCollectionView<VideoGame>(repository: VideoGameMediaRepository())
.task {
    self.items = try! await repository.getItems() as! [T]
}
.refreshable {
    self.items = try! await repository.getItems() as! [T]
}
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction 2 Next: Conclusion