Reputation: 13
Apple likes using method names like doThisWithPoint:
and doThisWithTouch:
for example and I thought—though I have such little XP that I'm probably wrong—that in Swift Apple wanted you to do signatures with doThis(withPoint : CGPoint)
and doThis(withTouch : UITouch)
and so you could overload the methods and when the bridge was created the Objective-C interface would look like doThisWithPoint
but now I'm getting an error saying that the selector doThis
already exists.
Any explanation as to what the best way to name and overload methods in Swift would be helpful. Not just what makes it run but what is the idiomatic way of doing it too. Thanks!
Upvotes: 0
Views: 153
Reputation: 290
I found this for you : Overload problem 1 and this Overload problem 2 One solution can be if you use different names to the methods.
To resolve this, use different names: like func perform1(operation: Type) and func perform2(operation: otherType).
Upvotes: 0
Reputation: 385600
From The Swift Programming Language:
By default, the external name of the first parameter is omitted, and the second and subsequent parameters use their local names as external names.
You need to include the withPoint
or withTouch
as part of the function name. Declare your methods in Swift like this:
class MyObject: NSObject {
func doThisWithPoint(point: CGPoint) {
}
func doThisWithTouch(touch: UITouch) {
}
}
Then you can call them in Objective-C like this:
[myObject doThisWithPoint:point];
[myObject doThisWithTouch:touch];
Upvotes: 1