 
         // Use a data detector to find urls in the text
         let plainText = attributedString.string
-        var error: NSError?
-        if let dataDetector = NSDataDetector(types: NSTextCheckingType.Link.rawValue, error: &error) {
-            let matches = dataDetector.matchesInString(plainText, options: NSMatchingOptions.ReportCompletion, range: NSMakeRange(0, count(plainText)))
+        do {
+            let dataDetector = try NSDataDetector(types: NSTextCheckingType.Link.rawValue)
+            let matches = dataDetector.matchesInString(plainText, options: NSMatchingOptions.ReportCompletion, range: NSMakeRange(0, plainText.characters.count))
 
             // Add a range entry for every url we found
             for match in matches {
-                if let textCheckingResult = match as? NSTextCheckingResult {
-                    let matchRange = textCheckingResult.range
-                    let stringIndexRange = advance(text.startIndex, matchRange.location)..<advance(text.startIndex, matchRange.location + matchRange.length)
-
-                    // If there's a link embedded in the attributes, use that instead of the raw text
-                    var realURL: AnyObject? = attributedString.attribute(NSLinkAttributeName, atIndex: matchRange.location, effectiveRange: nil)
-                    if realURL == nil {
-                        realURL = plainText.substringWithRange(advance(text.startIndex, matchRange.location)..<advance(text.startIndex, matchRange.location + matchRange.length))
-                    }
-
-                    if textCheckingResult.resultType == .Link {
-                        if let matchString = realURL as? String {
-                            rangesForURLs.append(LinkRangeResult(linkDetectionType: LinkDetectionType.URL, linkRange: stringIndexRange, linkString: matchString, textLink: nil))
-                        }
+                let matchRange = match.range
+                let stringIndexRange = text.startIndex.advancedBy(matchRange.location)..<text.startIndex.advancedBy(matchRange.location + matchRange.length)
+                
+                // If there's a link embedded in the attributes, use that instead of the raw text
+                var realURL: AnyObject? = attributedString.attribute(NSLinkAttributeName, atIndex: matchRange.location, effectiveRange: nil)
+                if realURL == nil {
+                    realURL = plainText.substringWithRange(text.startIndex.advancedBy(matchRange.location)..<text.startIndex.advancedBy(matchRange.location + matchRange.length))
+                }
+                
+                if match.resultType == .Link {
+                    if let matchString = realURL as? String {
+                        rangesForURLs.append(LinkRangeResult(linkDetectionType: LinkDetectionType.URL, linkRange: stringIndexRange, linkString: matchString, textLink: nil))
                     }
                 }
             }
+        } catch _ as NSError {
+            
         }
 
         return rangesForURLs
     }
     
     private func addLinkAttributesToAttributedString(attributedString: NSAttributedString, withLinkRangeResults linkRangeResults: [LinkRangeResult], highlighted: Bool = false) -> NSAttributedString {
-        var mutableAttributedString = NSMutableAttributedString(attributedString: attributedString)
+        let mutableAttributedString = NSMutableAttributedString(attributedString: attributedString)
         
         for linkRangeResult in linkRangeResults {
-            var attributes: [NSObject: AnyObject]?
+            var attributes: [String: AnyObject]?
             
             if linkRangeResult.linkDetectionType == .TextLink {
                 let color = highlighted ? privateTextLinkHighlightedTextColor : textLinkTextColor

        super.touchesEnded(touches, withEvent: event)
    }
    
    public override func touchesCancelled(touches: Set<NSObject>, withEvent event: UIEvent!) {
        addLinkAttributesToLinkRangeResultWithTouches(touches, highlighted: false)
        super.touchesCancelled(touches, withEvent: event)
    }
    
    // MARK: Functions
    
    func addAttributes(attributes: Dictionary<NSObject, AnyObject>, range: NSRange) {
        if let contextLabelData = contextLabelData {
            var mutableAttributedString = NSMutableAttributedString(attributedString: contextLabelData.attributedString)
            mutableAttributedString.addAttributes(attributes, range: range)
            
            contextLabelData.attributedString = mutableAttributedString

                attributes = attributesWithTextColor(color)
            }
            
            if let attributes = attributes {
                let location = text.startIndex.distanceTo(linkRangeResult.linkRange.startIndex)
                let length = linkRangeResult.linkRange.startIndex.distanceTo(linkRangeResult.linkRange.endIndex)
                let range = NSMakeRange(location, length)
                
                mutableAttributedString.setAttributes(attributes, range: range)
            }
        }
        
