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{ | |
| var length: Int{ | |
| get{ | |
| return self.utf16Count | |
| } | |
| } | |
| func isValidEmail() -> Bool { | |
| let emailRegex = NSRegularExpression(pattern: "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$", options: .CaseInsensitive, error: nil) |
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
| func uicolorFromHex(rgbValue:UInt32)->UIColor{ | |
| let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0 | |
| let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0 | |
| let blue = CGFloat(rgbValue & 0xFF)/256.0 | |
| return UIColor(red:red, green:green, blue:blue, alpha:1.0) | |
| } |
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 NSTimer { | |
| class func scheduledTimerWithTimeInterval(interval: NSTimeInterval, repeats: Bool, handler: NSTimer! -> Void) -> NSTimer { | |
| let fireDate = interval + CFAbsoluteTimeGetCurrent() | |
| let repeatInterval = repeats ? interval : 0 | |
| let timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, fireDate, repeatInterval, 0, 0, handler) | |
| CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes) | |
| return timer | |
| } | |
| } | |
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
| func listEntities(managedContext: NSManagedObjectContext, entityName: String, groupBy: Array<String>)->NSArray{ | |
| var error: NSError? | |
| var results : NSArray = NSArray() | |
| let fetchRequest = NSFetchRequest(entityName: entityName) | |
| if groupBy.count > 0{ | |
| fetchRequest.propertiesToGroupBy = groupBy | |
| } | |
| if let results = managedContext.executeFetchRequest(fetchRequest, error: &error) { |
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
| func delay(delay:Double, closure:()->()) { | |
| dispatch_after( | |
| dispatch_time( | |
| DISPATCH_TIME_NOW, | |
| Int64(delay * Double(NSEC_PER_SEC)) | |
| ), | |
| dispatch_get_main_queue(), closure) | |
| } |
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
| NSString *path = [[NSBundle mainBundle] pathForResource:@"document" ofType:@"pdf"]; | |
| NSURL *targetURL = [NSURL fileURLWithPath:path]; | |
| NSURLRequest *request = [NSURLRequest requestWithURL:targetURL]; | |
| [webView loadRequest:request]; |
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
| <plist version="1.0"> | |
| <array> | |
| <dict> | |
| <key>category</key> <string>classic</string> | |
| <key>quote</key> <string>Frankly my dear, I don't give a dam.</string> | |
| <key>source</key> <string>Gone with the wind</string> | |
| </dict> |
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
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| previewToSave = nil; | |
| CGSize screenSize = self.view.bounds.size; | |
| float scaleFactor = 0.2; | |
| const size_t originalWidth = screenSize.width * scaleFactor; | |
| const size_t originalHeight = screenSize.height * scaleFactor; | |
| CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); | |
| CGContextRef ctx = CGBitmapContextCreate(nil, originalWidth, originalHeight, 8, 4*(int)originalWidth, colorSpaceRef, kCGImageAlphaPremultipliedLast); | |
| if (ctx != nil) { |
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
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| previewToSave = nil; | |
| CGSize screenSize = self.view.bounds.size; | |
| float scaleFactor = 0.2; | |
| const size_t originalWidth = screenSize.width * scaleFactor; | |
| const size_t originalHeight = screenSize.height * scaleFactor; | |
| CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); | |
| CGContextRef ctx = CGBitmapContextCreate(nil, originalWidth, originalHeight, 8, 4*(int)originalWidth, colorSpaceRef, kCGImageAlphaPremultipliedLast); | |
| if (ctx != nil) { |
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
| double delayInSeconds = 2.0; | |
| dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); | |
| dispatch_after(popTime, dispatch_get_main_queue(), ^(void) { |