Reputation: 1664
I have a protocol which has a struct as a property:
struct Dimensions {
var width: CGFloat
var height: CGFloat
}
Protocol ShapeType {
var dimensions: Dimensions {get set}
}
Now I have a class which is a subclass of SKShapeNode
:
class Shapes: SKShapeNode, ShapeType {
var dimensions: Dimensions
override init { // Error
super.init()
dimensions = Dimensions(width: 40, height: 40)
}
}
I get this error:
Property 'self.dimensions' not initialized at super.init call
What is the proper way to inisialzie the struct inside the class?
Upvotes: 0
Views: 3218
Reputation: 548
You have to initialize self.dimensions before you call the super.init() method in your Shapes class initializer
init(dimensions: Dimensions) {
self.dimensions = dimensions
super.init()
}
Upvotes: 2