Introduction to Object-Oriented Programming

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

Lesson 02: Classes & Structs

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

You’re about to define a MuseumObject type for your MetMuseum app. In this demo, I’m using an Xcode playground and writing in Swift. If you’re following along, start up Xcode and open the module1-lesson2 playground in the starter folder.

let objectID: Int
let title: String
let objectURL: String
let primaryImageSmall: String
let creditLine: String
let isPublicDomain: Bool
let object_pd =
MuseumObject(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",
             isPublicDomain: true)
let object =
MuseumObject(objectID: 13061,
             title: "Cypress and Poppies",
             objectURL: "https://www.metmuseum.org/art/collection/search/13061",
             primaryImageSmall: "",
             creditLine: "Gift of Iola Stetson Haverstick, 1982",
             isPublicDomain: false)
let obj = MuseumObject(
class MuseumObject {
  ...
}
init(objectID: Int,
     title: String,
     objectURL: String,
     primaryImageSmall: String,
     creditLine: String,
     isPublicDomain: Bool) {
  self.objectID = objectID
  self.title = title
  self.objectURL = objectURL
  self.primaryImageSmall = primaryImageSmall
  self.creditLine = creditLine
  self.isPublicDomain = isPublicDomain
}
if isPublicDomain {
  PlaygroundPage.current.setLiveView(MuseumObjectView(object: self))
} else {
  guard let url = URL(string: objectURL) else { return }
  PlaygroundPage.current.liveView = SFSafariViewController(url: url)
}
object_pd.showImage()
object.showImage()
var title: String
struct MuseumObject {
var object2 = object_pd
object2.title = "Sunflowers"
class MuseumObject {
let object2 = object_pd
func changeTitle(to newTitle: String) {
  title = newTitle
}
object2.changeTitle(to: "Sunflowers")
mutating func changeTitle(to newTitle: String) {
object2 .showImage()
private let isPublicDomain: Bool
if object.isPublicDomain { }
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction Next: Conclusion