main.swift238 chars13 lines
In the example above, we define a struct Car
, which has three properties: brand
and model
are of type String
, and year
is of type Int
. We also define a beep
function that just prints "beep" to the console.
We create an instance of the Car
struct with the let myCar = Car(brand: "Toyota", model: "Corolla", year: 2020)
statement, passing in the brand, model, and year as arguments to the initializer. Finally, we call the beep
function on the myCar
instance with myCar.beep()
, which prints "beep" to the console.
gistlibby LogSnag