Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift Invalid Redeclaration

Tags:

ios

swift

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

like image 374
mkayaa93 Avatar asked Dec 05 '14 07:12

mkayaa93


3 Answers

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) {        
}
like image 98
Leo Dabus Avatar answered Nov 12 '22 12:11

Leo Dabus


I had the same issue, I've solved it by deleting an extra file in the compile sources.

  1. Go your project root directory.
  2. Go to Build Phases.
  3. Click on Compile Sources, check for a file that has been added twice and delete one of them.

That should solve your problem.

like image 33
J. Koush Avatar answered Nov 12 '22 13:11

J. Koush


I had this exact error message just right now. For me it was a class and a struct conflict.

For any two declaration of types in the same scope, you will get an error e.g. if you use any of declare any of the 2 types below, you will get an error

class employee{...}
struct employee{...}
func employee(){...}
protocol employee{...}

It's not just for classes, structs or func, it's for everything because funcs, structs, enums, protocols are all First class citizens in Swift

like image 2
mfaani Avatar answered Nov 12 '22 12:11

mfaani