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


// 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


private struct LabelCharacterFinder: CharacterFinder {
    typealias ViewType = UILabel

    /**
     Finds the character at a given location in a tapped view.

     :param: view        The view that was tapped. Must be an instance of UILabel.
     :param: tapLocation The location of the tap. Usually derived from a gesture recognizer.

     :returns: The index of the tapped character.
     */
    static func indexOfTappedCharacter(inView view: ViewType, tapLocation: CGPoint) -> Int {

        // UILabel doesn't come with NSTextStorage, NSTextContainer, or NSLayoutManager, so
        // we have to create these manually.

        let attributedText = view.attributedText ?? NSAttributedString()
        let textStorage = NSTextStorage(attributedString: attributedText)
        let layoutManager = NSLayoutManager()
        textStorage.addLayoutManager(layoutManager)

        let textContainer = NSTextContainer(size: view.bounds.size)
        textContainer.lineFragmentPadding = 0
        textContainer.maximumNumberOfLines = view.numberOfLines
