 /**
 *  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.
-    */
+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.
-*/
-class MentionTapHandler: NSObject {
-    
+/// 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.
-    */
+
+    /**
+     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)

    static let Encoded = "MentionEncodedAttribute"
}

/**
*  The MentionController class provides a simple interface for rendering @mentions and #hashtag comments on UILabel, UITextField, and UITextView.
*  To handle user taps on an @mentioin or #hashtag you must conform to the MentionTapHandlerDelegate protocol and set the delegate on MentionController.
*  Note: MentionController is built to be compatible objective C.
*/
class MentionController: NSObject, MentionTapHandlerDelegate {
    
    var view: UIView
    weak var delegate: MentionTapHandlerDelegate?
    private var tapHandler: MentionTapHandler!
    private let mentionDecoder = MentionDecoder()
    
    // MARK: Init
    
    convenience init(label: UILabel, delegate: MentionTapHandlerDelegate?) {
        label.userInteractionEnabled = true
        self.init(view: label, inputString: label.text, delegate: delegate)
    }
    
    convenience init(textField: UITextField, delegate: MentionTapHandlerDelegate?) {
        self.init(view: textField, inputString: textField.text, delegate: delegate)
    }
    
    convenience init(textView: UITextView, delegate: MentionTapHandlerDelegate?) {
        self.init(view: textView, inputString: textView.text, delegate: delegate)
    }
    
    private init(view: UIView, inputString: String?, delegate: MentionTapHandlerDelegate?) {
        self.view = view
        self.delegate = delegate
        super.init()
        
        // Decode
        if let string = inputString {
            if let attributedStringWithMentions = mentionDecoder.decode(string) {
                switch view {
                case let label as UILabel:
                    label.attributedText = attributedStringWithMentions
                case let textView as UITextView:
                    textView.attributedText = attributedStringWithMentions
                case let textField as UITextField:
                    textField.attributedText = attributedStringWithMentions
                default:
                    print("unsupported view")
                }
            }
        }
        
        // Handle Taps
        tapHandler = MentionTapHandler(view: view, delegate: self)
    }
    
    // MARK: MentionTapHandlerDelegate
    
    func userTappedWithId(id: String) {
        delegate?.userTappedWithId(id)
    }
}

        default:
            print("unsupported view")
        }

        if let index = charIndex {
            if let userId = attributedString?.attribute(MentionAttributes.UserId, atIndex: index, effectiveRange: nil) as? String {
                delegate?.userTappedWithId(userId)
