-6

function x is written with different parameter Name

func x(cell:Int)  { }      
func x(onCell:Int){ }//will Not give compile time error because it treats as different name    
func x(withCell:Int){}//For this Line Compile time error is coming why??

//: Method 'x(withCell:)' with Objective-C selector 'xWithCell:' conflicts with method 'x(cell:)' with the same Objective-C selector

adev
  • 2,052
  • 1
  • 21
  • 33
Mayur Mehta
  • 99
  • 1
  • 9
  • 2
    This is neither Objective-C nor Swift. – jscs Aug 16 '17 at 12:28
  • This is a valid question in swift and not a duplicate of other question. People are quick to judge and close it. It is really tough for a new person to ask question in SO. His title was wrong and that caused all confusion but if you read question it is about overloading in swift. – adev Aug 17 '17 at 17:36
  • 1
    @Mayur, the issue is that in ObjC swift functions `x(cell:)` and `x(withCell:)` are converted to `xWithCell:`. That is why it doesn't allow that. Other function you wrote is converted to `xOnCell:` which is a different method compared to this. This has nothing to do with overloading in ObjC as it is not overloading. – adev Aug 17 '17 at 17:40
  • Please reopen the question. The question tagged as duplicate and this question has nothing in common. This is not method overloading and this question is about how swift converts its functions to ObjC, not about how ObjC does overloading. – adev Aug 17 '17 at 22:28
  • @adev I guess you might be right.I Can't re-Open this,I don't have priveldge – Mayur Mehta Aug 20 '17 at 10:35

1 Answers1

1

Posting my comment as an answer:

The issue is that in ObjC swift functions x(cell:) and x(withCell:) are converted to xWithCell:. That is why it doesn't allow that. Other function you wrote is converted to xOnCell: which is a different method compared to this. This has nothing to do with overloading in ObjC as it doesn't fall into overloading. It is just a different function signature. Hope that helps.

adev
  • 2,052
  • 1
  • 21
  • 33