Skip to content

Instantly share code, notes, and snippets.

View lukewakeford's full-sized avatar
🚲
Cycling

Luke Wakeford lukewakeford

🚲
Cycling
View GitHub Profile
@lukewakeford
lukewakeford / Swift String Extensions
Last active January 5, 2016 10:26
Swift String Extensions
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 {
@lukewakeford
lukewakeford / Swift UIColor Extensions
Last active January 5, 2016 10:26
Swift UIColor Extensions
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)
@lukewakeford
lukewakeford / Swift NSDate Extensions
Last active August 31, 2016 18:43
Swift NSDate Extensions
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 {