1
votes

I got this error message after upgrade from XCode 6.2 to XCode 7.0.1.

/Users/ZERO/Documents/Xcode/XXXXX/Library/SegmentedControl/SegmentedControl.swift:124:10: Method 'beginTrackingWithTouch(:withEvent:)' with Objective-C selector 'beginTrackingWithTouch:withEvent:' conflicts with method 'beginTrackingWithTouch(:withEvent:)' from superclass 'UIControl' with the same Objective-C selector

My code:

func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent) -> Bool {

    let location = touch.locationInView(self)

    var calculatedIndex : Int?
    for (index, item) in labels.enumerate() {
        if item.frame.contains(location) {
            calculatedIndex = index
        }
    }


    if calculatedIndex != nil {
        selectedIndex = calculatedIndex!
        sendActionsForControlEvents(.ValueChanged)
    }

    return false
}
1

1 Answers

2
votes

The method it has the almost same signature is defined in UIContol.

beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?)

The difference is event parameter has been optional.

So the compiler cannot distinguish them. .

If you'd like to override beginTrackingWithTouch() method, you can change the type of event parameter to UIEvent?, and add override annotation like following:

override func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool {
    ...

    return false
}