         textContainer.layoutManager = layoutManager
 
         layoutManager.addTextContainer(textContainer)
-        layoutManager.textStorage = textStorage
-        
+
         // Find the tapped character
-        
+
         return layoutManager.characterIndexForPoint(tapLocation, inTextContainer: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
     }
 }
 
 private struct TextViewCharacterFinder: CharacterFinder {
     typealias ViewType = UITextView
-    
-    /**
-    Finds the character at a given location in a tapped view.
-    
-    :param: view        The view that was tapped. Must be an instance of UITextView.
-    :param: tapLocation The location of the tap. Usually derived from a gesture recognizer.
-    
-    :returns: The index of the tapped character.
-    */
+
+    /**
+     Finds the character at a given location in a tapped view.
+
+     :param: view        The view that was tapped. Must be an instance of UITextView.
+     :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 {
-        
+
         // Location of the tap
-        
+
         var location = tapLocation
         let layoutManager = view.layoutManager
         location.x -= view.textContainerInset.left
         location.y -= view.textContainerInset.top
-        
+
         // Find the tapped character
-        
+
         return layoutManager.characterIndexForPoint(location, inTextContainer: view.textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
     }
 }
 
 private struct TextFieldCharacterFinder: CharacterFinder {
     typealias ViewType = UITextField
-    
-    /**
-    Finds the character at a given location in a tapped view.
-    
-    :param: view        The view that was tapped. Must be an instance of UITextField.
-    :param: tapLocation The location of the tap. Usually derived from a gesture recognizer.
-    
-    :returns: The index of the tapped character.
-    */
+
+    /**
+     Finds the character at a given location in a tapped view.
+
+     :param: view        The view that was tapped. Must be an instance of UITextField.
+     :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 {
-        
+
         // UITextField doesn't come with NSTextStorage, NSTextContainer, or NSLayoutManager, so
         // we have to create these manually.
-        
+
         var charIndex = -1
-        
+
         if let attributedText = view.attributedText {
             let textStorage = NSTextStorage(attributedString: attributedText)
             let layoutManager = NSLayoutManager()
             textStorage.addLayoutManager(layoutManager)
-            
+
             let textContainer = NSTextContainer(size: view.bounds.size)
             textContainer.lineFragmentPadding = 0
             textContainer.layoutManager = layoutManager


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

/**
*  MentionTapHandlerDelegate defines functions for handling taps on @mention and #hashtag substrings.
*/
public protocol MentionTapHandlerDelegate: class {
    /**
     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.
public 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)
