Delete Option Not Appearing

I have entered the code and the “Delete” button does not appear. In the compiler the machine recognized a single Tap has occured but nothing happens. What I am doing wrong?

 func tap(_ gestureRecognizer: UIGestureRecognizer){
    print("Recognized a tap")
    let point = gestureRecognizer.location(in: self)
    selectedLineIndex = indexOfLine(at: point)
    
    // Grab the menu controller 
    let menu = UIMenuController.shared
    
    if selectedLineIndex != nil {
        
        //Make DrawView the target of menu item action messages 
        becomeFirstResponder()
        
        //Create a new "Delete" UIMenuItem
        let deleteItem = UIMenuItem(title: "Delete",action: #selector(DrawView.deleteLine(_:)))
        menu.menuItems = [deleteItem]
        
        //Tell the menu where it should come from and show it
        let targetRect = CGRect(x: point.x, y: point.y, width: 2, height: 2)
        menu.setTargetRect(targetRect, in: self)
        menu.setMenuVisible(true, animated: true)
    }else {
        
        //Hide the menu if no line is selected 
        menu.setMenuVisible(false, animated: true)
    
    
    }
    
    setNeedsDisplay()
    
}

override var canBecomeFirstResponder: Bool {
    return true
}

func deleteLine(_ sender: UIMenuController) {
    //Remove the selected line from the list of finishedLines
    if let index = selectedLineIndex {
        finishedLines.remove(at: index)
        selectedLineIndex = nil
        
        //Redraw everything
        setNeedsDisplay()
        
    }
}

I got it. It was in this area, Return index was not entered

 func indexOfLine(at point: CGPoint) -> Int? {
    //Find a line close to point
    for (index, line) in finishedLines.enumerated() {
        let begin = line.begin
        let end = line.end
        
    //Check a few points on the line 
        for t in stride(from: CGFloat(0), to: 1.0, by: 0.05) {
        let x = begin.x + ((end.x - begin.x) * t)
        let y = begin.y + ((end.y - begin.y) * t)
            
        //If the tapped point is within 20 points, lets return this line 
            if hypot(x - point.x, y - point.y) < 20.0 {
            return index
            
        }
    }
}