I am new to Swift and following the online documentation. Specifically I'm looking at Initialization (https://docs.swift.org/swift-book/LanguageGuide/Initialization.html).
Under the sub-heading 'Memberwise Initializers for Structure Types', it says:
When you call a memberwise initializer, you can omit values for any properties that have default values. In the example above, the Size structure has a default value for both its height and width properties. You can omit either property or both properties, and the initializer uses the default value for anything you omit
and then provides an example:
struct Size {
var width = 0.0, height = 0.0
}
let twoByTwo = Size(width: 2.0, height: 2.0)
let zeroByTwo = Size(height: 2.0)
print(zeroByTwo.width, zeroByTwo.height)
// Prints "0.0 2.0"
let zeroByZero = Size()
print(zeroByZero.width, zeroByZero.height)
// Prints "0.0 0.0"
If I try that, however, I get an error for the initialization of zeroByTwo:
Cannot invoke initializer for type 'Size' with an argument list of type '(height: Double)'
Have I misunderstood something?
I am using Swift 5.