mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-09 08:16:58 +02:00
[swift/en] describe convenience initializers (#4836)
This commit is contained in:
@@ -679,6 +679,9 @@ class Rect: Shape {
|
|||||||
|
|
||||||
// A simple class `Square` extends `Rect`
|
// A simple class `Square` extends `Rect`
|
||||||
class Square: Rect {
|
class Square: Rect {
|
||||||
|
// Use a convenience initializer to make calling a designated initializer faster and more "convenient".
|
||||||
|
// Convenience initializers call other initializers in the same class and pass default values to one or more of their parameters.
|
||||||
|
// Convenience initializers can have parameters as well, which are useful to customize the called initializer parameters or choose a proper initializer based on the value passed.
|
||||||
convenience init() {
|
convenience init() {
|
||||||
self.init(sideLength: 5)
|
self.init(sideLength: 5)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user