Created
October 30, 2014 03:24
-
-
Save s-aska/ad92c43b45b9024b896d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SwifteriOS | |
struct TwitterVia { | |
let name: String | |
let URL: NSURL? | |
struct Static { | |
static let regexp = NSRegularExpression(pattern: "<a href=\"(.+)\" rel=\"nofollow\">(.+)</a>", options: NSRegularExpressionOptions(0), error: nil)! | |
} | |
init(_ source: String) { | |
if let match = Static.regexp.firstMatchInString(source, options: NSMatchingOptions(0), range: NSMakeRange(0, countElements(source))) { | |
if match.numberOfRanges > 0 { | |
self.URL = NSURL(string: (source as NSString).substringWithRange(match.rangeAtIndex(1)) as String) | |
self.name = (source as NSString).substringWithRange(match.rangeAtIndex(2)) | |
return | |
} | |
} | |
self.name = source | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment