#6: Memberwise Initializers
Question
// Swift Quiz
— objc.io (@objcio) March 27, 2019
struct IntegralSize {
var width: Int
var height: Int
init(_ size: CGSize) {
self.width = Int(size.width)
self.height = Int(size.height)
}
}
let size = IntegralSize(width: 50, height: 50)
// What is size?
Solution
Solution: Compiler error (Extra argument 'height' in call)
— objc.io (@objcio) March 28, 2019
When we define a custom initializer within a struct, we don't get the standard memberwise initializer.
Therefore, the initializer taking a CGSize is the only one available.https://t.co/s7500CWmAg