Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

Function Inside Swift Struct

struct Car {

  var gear = 0

  // method inside struct
  func applyBrake(){
  print("Applying Hydraulic Brakes")
  }
}

// create an instance 
var car1 = Car()

car1.gear = 5

print("Gear Number: (car1.gear)")
// access method
car1.applyBrake()
 
PREVIOUS NEXT
Tagged: #Function #Inside #Swift #Struct
ADD COMMENT
Topic
Name
5+5 =