Skip to content

Instantly share code, notes, and snippets.

@maheshgawali
Last active August 25, 2020 13:37
Show Gist options
  • Save maheshgawali/c5e55f3fef2e981e0188cf7567cc3a20 to your computer and use it in GitHub Desktop.
Save maheshgawali/c5e55f3fef2e981e0188cf7567cc3a20 to your computer and use it in GitHub Desktop.
explore whats happening here in swift?
class Car {
var plate: String
var driver: Driver?
init(plate: String) {
self.plate = plate
}
}
class Driver {
let name: String
var cars: [Car] = []
init(name: String) {
self.name = name
}
}
var myCar: Car? = Car(plate: "ABC123")
var myDriver: Driver? = Driver(name: "Neo")
myCar?.driver = myDriver
if let car = myCar {
myDriver?.cars.append(car)
}
myCar = nil
myDriver = nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment