coolly coolly - 7 months ago 9
Swift Question

How can I allow my function to accepts two different objects in swift?

I have a function which takes one argument. I wanted my function to accept two object types. How can I do it? Here is the example below:

func accept(user: Customer) {
...
}


It should accept Customer and Employee object reference.

accept(objRefCustomer)
accept(objRefEmployee)


Please help me in this case.

Answer

You can create a super class called People of Cutomer and Employee.

Then set user as type of People:

func accept(user: People) {
  ...
}