Last active
August 25, 2020 13:37
-
-
Save maheshgawali/c5e55f3fef2e981e0188cf7567cc3a20 to your computer and use it in GitHub Desktop.
explore whats happening here in swift?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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