我正在将我的现有 Objective-C 项目转换为 Swift。我正在转换一个函数,在该函数中出现了上述错误。请检查下面的代码。
Objective-C
这是快速代码。
请问有人可以告诉我我做错了什么吗?
Objective-C
- (IBAction)accessoryButtonTapped:(id)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
if (indexPath != nil) {
[self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
}
}
这是快速代码。
@IBAction func accessoryButtonTapped(sender: AnyObject, event: AnyObject) {
let touches: Set<AnyObject> = event.allTouches()! // I am getting the ERROR here
let touch: UITouch = touches.first!
let currentTouchPosition: CGPoint = touch.locationInView(self.tableView)
let indexPath: NSIndexPath = self.tableView.indexPathForRowAtPoint(currentTouchPosition)!
self.tableView(self.tableView, accessoryButtonTappedForRowWithIndexPath: indexPath)
}
请问有人可以告诉我我做错了什么吗?