mkayaa93 mkayaa93 - 2 months ago 80
Swift Question

swift Invalid Redeclaration

func dropShape() {
if let shape = fallingShape {
while detectIllegalPlacement() == false {
shape.lowerShapeByOneRow()
}
shape.raiseShapeByOneRow()
delegate?.gameShapeDidDrop(self)
}
}


Hi, I'm taking this Invalid redeclaration of 'dropShape()' so what did I wrong. Can anybody help me

Answer

That error message means that you have created two functions with the same name.

enter image description here

You can not use same name and same signature for function. Yes function overloading is there and it means that you can use same name with different parameters. You can create as many function as you want using same name. The thumb rule is each overloading function must have different parameters.

For Example:

func dropShape() {        
}

func dropShape(points: CGPoint) {        
}