         default:
             print("unsupported view")
         }
-        
+
         if let index = charIndex {
             if let userId = attributedString?.attribute(MentionAttributes.UserId, atIndex: index, effectiveRange: nil) as? String {
                 delegate?.userTappedWithId(userId)

/**
*  MentionTapHandlerDelegate defines functions for handling taps on @mention and #hashtag substrings.
*/
@objc protocol MentionTapHandlerDelegate {
    /**
    This method is called when the user taps an @mention string.
    
    :param: id The id encoded in the @mention string.
    */
    func userTappedWithId(id: String)
}

/**
*  Listens for taps on the supplied view and calls the corresponding MentionTapHandlerDelegate method.
*  Note: Creates an instance of UITapGestureRecognizer on the supplied UIView.
*/
class MentionTapHandler: NSObject {
    
    var tapRecognizer: UITapGestureRecognizer!
    weak var delegate: MentionTapHandlerDelegate?
    
    init(view: UIView, delegate: MentionTapHandlerDelegate) {
        super.init()
        self.delegate = delegate
        tapRecognizer = UITapGestureRecognizer(target: self, action: "viewTapped:")
        view.addGestureRecognizer(tapRecognizer)
    }
    
    /**
    Called every time the user taps the supplied view. If the user tapped an @mention or a hashtag, the corresponding
    MentionTapHandlerDelegate delegate is called on the delegate property.
    
    :param: recognizer An instance of UITapGestureRecognizer created in the MentionTapHandler initializer.
    */
    func viewTapped(recognizer: UITapGestureRecognizer) {
        recognizer.cancelsTouchesInView = false
        
        let view = recognizer.view!
        let location = recognizer.locationInView(view)
        var charIndex: Int?
        var attributedString: NSAttributedString?
        
        switch view {
        case let label as UILabel:
            charIndex = LabelCharacterFinder.indexOfTappedCharacter(inView: label, tapLocation: location)


// MARK: - CharacterFinder


/**
*  CharacterFinder is a protocol for a class that identifies what character was tapped in the given container of text.
The container class type is at the discretion of the class or struct that implements CharacterFinder.
*/
private protocol CharacterFinder {
    typealias ViewType: UIView
