Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

Initializer Swift

class Bike {

  // properties with no default values
  var name: String
  var gear: Int

  // assign value using initializer
  init(name: String, gear: Int){
    self.name = name
    self.gear = gear
  }
}

// object of Person with custom initializer 
var bike1 = Bike(name: "BMX Bike", gear: 2)

print("Name: (bike1.name) and Gear: (bike1.gear)")
 
PREVIOUS NEXT
Tagged: #Initializer #Swift
ADD COMMENT
Topic
Name
1+9 =