Home / IOS Development / Need help understanding how init () works in Swift: iOSProgramming

Need help understanding how init () works in Swift: iOSProgramming



My understanding of init () is that it is necessary to initialize properties in a class, that is, to give initial values ​​for the constant or variable properties we have in the class. Can anyone help me understand what Swift does when we write ourselves. Width is equal to the width parameter. Does self-width refer to the variable property width, and a value given to the width will be sent to our variable property?

Example:

Class Box {
var width: Int
var height: Int

init(width: Int, height: Int) {
self.width = width
self.height = height
}

Source link