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
public func flushCookies() { | |
let storage = NSHTTPCookieStorage.sharedHTTPCookieStorage() | |
if let cookieJar = storage.cookies as? [NSHTTPCookie] { | |
for cookie in cookieJar { storage.deleteCookie(cookie) } | |
} | |
NSUserDefaults.standardUserDefaults().synchronize() | |
} |
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
public func delay(time: Double, completion: () -> Void) { | |
let ms = dispatch_time(DISPATCH_TIME_NOW, Int64(time * Double(NSEC_PER_SEC))) | |
dispatch_after(ms, dispatch_get_main_queue()) { | |
() -> Void in | |
completion() | |
} | |
} | |
public func delay(time: Double) -> (()->Void) -> Void { | |
return { |
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
// MARK: - UIImage (Base64 Encoding) | |
public enum ImageFormat { | |
case PNG | |
case JPEG(CGFloat) | |
} | |
extension UIImage { | |
public func base64(format: ImageFormat) -> String { |
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
// MARK: - NSError | |
public enum ErrorType: Int { | |
case Unknown = 1 | |
case NotAuthenticated = 2 | |
func localizedUserInfo() -> [String: String] { | |
var localizedDescription: String = "" | |
var localizedFailureReasonError: String = "" |
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
// MARK: - Box | |
final public class Box<T> { | |
public let unbox:T | |
public init(_ value: T) { self.unbox = value } | |
} | |
// MARK: - Result enum | |
public enum Result<T: Printable> { |
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
public enum NotificationKey: String { | |
case UserSignedIn = "UserSignedInNotification" | |
case UserSignedOut = "UserSignedOutNotification" | |
case SomeOtherEvent = "SomeOtherEventNotification" | |
} | |
extension NSNotificationCenter { | |
func addObserver(observer: AnyObject, selector aSelector: Selector, key aKey: NotificationKey) { | |
self.addObserver(observer, selector: aSelector, name: aKey.rawValue, object: nil) |
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
- (BOOL)addSkipBackupAttribute{ | |
if (![[NSFileManager defaultManager] fileExistsAtPath:[self path]]) return NO; | |
NSError *error = nil; | |
BOOL success = [self setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error]; | |
if(!success){ | |
NSLog(@"Error excluding %@ from backup %@", [self lastPathComponent], error); | |
} | |
return success; | |
} |
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
#define FLT_EQUAL(a, b) (fabs((a) - (b)) < FLT_EPSILON) | |
#define FLT_ZERO(a) (fabs(a) < FLT_EPSILON) |
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
NSArray *fontFamilies = [UIFont familyNames]; | |
for (int i = 0; i < [fontFamilies count]; i++){ | |
NSString *fontFamily = fontFamilies[i]; | |
NSArray *fontNames = [UIFont fontNamesForFamilyName:fontFamilies[i]]; | |
NSLog (@"%@: %@", fontFamily, fontNames); | |
} |
NewerOlder