Introduction to Object-Oriented Programming

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

Lesson 03: Inheritance & Polymorphism

Demo

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

In this demo, you’ll create a subclass of MuseumObject. You’ll move primaryImageSmall to this subclass, then learn how to write the subclass’s init and override showImage().

let primaryImageSmall: String
primaryImageSmall: String,
self.primaryImageSmall = primaryImageSmall
primaryImageSmall: "https://images.metmuseum.org/CRDImages/ep/original/DT1567.jpg",
guard let url = URL(string: objectURL) else { return }
PlaygroundPage.current.liveView = SFSafariViewController(url: url)
class PublicDomainObject: MuseumObject {
  
}
let primaryImageSmall: String
init(objectID: Int,
     title: String,
     objectURL: String,
     primaryImageSmall: String, 
     creditLine: String, = tru
     isPublicDomain: Bool = true) { }   
self.primaryImageSmall = primaryImageSmall
super.init(objectID: objectID,
           title: title,
           objectURL: objectURL,
           creditLine: creditLine,
           isPublicDomain: isPublicDomain)
override func showImage() {
  PlaygroundPage.current.setLiveView(MuseumObjectView(object: self))
}
let object: PublicDomainObject
let object_pd =
PublicDomainObject(objectID: 436535,
                   title: "Wheat Field with Cypresses",
                   objectURL: "https://www.metmuseum.org/art/collection/search/436535",
                   primaryImageSmall: "https://images.metmuseum.org/CRDImages/ep/original/DT1567.jpg"
                   creditLine: "Purchase, The Annenberg Foundation Gift, 1993")
object.showImage()
object_pd.showImage()
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction Next: Conclusion