This file contains hidden or 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
extension String { | |
func isEmail() -> Bool { | |
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}" | |
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx) | |
return emailTest.evaluateWithObject(self) | |
} | |
func convertStringToDictionary() -> [String:AnyObject]? { | |
if let data = self.dataUsingEncoding(NSUTF8StringEncoding) { | |
do { |
This file contains hidden or 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
extension UIColor { | |
class func fromHexString(hex:String) -> UIColor { | |
let hex = hex.stringByTrimmingCharactersInSet(NSCharacterSet.alphanumericCharacterSet().invertedSet) | |
var int = UInt32() | |
NSScanner(string: hex).scanHexInt(&int) | |
let a, r, g, b: UInt32 | |
switch hex.characters.count { | |
case 3: // RGB (12-bit) | |
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17) | |
case 6: // RGB (24-bit) |
This file contains hidden or 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
extension NSDate { | |
convenience init(ISO8601:String) { | |
let dateStringFormatter = NSDateFormatter() | |
dateStringFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" | |
dateStringFormatter.locale = NSLocale.systemLocale() | |
let d = dateStringFormatter.dateFromString(ISO8601) | |
self.init(timeInterval:0, sinceDate:d!) | |
} | |
class func getLastDayOfMonthFrom(month:Int,year:Int) -> NSDate { |
NewerOlder