swift Invalid Redeclaration

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) {        
}

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


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.

Tags:

Ios

Swift