user3255746
user3255746

Reputation: 1437

Swift 3 conversion "has no member" error

I am trying to convert my project to Swift 3, and have gotten most of the bugs handled but I am having issues calling my gesture recognizer. Here is my code:

func addGestureToView(toView: UIView) {
    let gesutereUp = Init(UISwipeGestureRecognizer(target: self, action: #selector(DemoViewController.swipeHandler(_:)))) {
      $0.direction = .Up
    }

    let gesutereDown = Init(UISwipeGestureRecognizer(target: self, action: #selector(DemoViewController.swipeHandler(_:)))) {
      $0.direction = .Down
    }
    toView.addGestureRecognizer(gesutereUp)
    toView.addGestureRecognizer(gesutereDown)
  }

  func swipeHandler(sender: UISwipeGestureRecognizer) {
    let indexPath = NSIndexPath(forRow: currentIndex, inSection: 0)
    guard let cell  = collectionView?.cellForItemAtIndexPath(indexPath) as? DemoCollectionViewCell else { return }

It gives me and error stating that both gestureUp and gestureDown has "no member 'swipeHandler'"

Also on the row "let indexPath..." I get an error saying "Argument labels '(forRow, in section:)' do not match any available overloads"

Can someone help out with the conversion fix for Swift 3? When I comment those lines out everything works so this is the last piece. Thanks in advance.

Upvotes: 0

Views: 917

Answers (1)

Jans
Jans

Reputation: 11250

Replace the underscore for label sender in the selector.

#selector(DemoViewController.swipeHandler(sender:))

About the index path, the new method in swift3 is:

NSIndexPath(row: currentIndex, section: 0)

Upvotes: 1

Related Questions