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 UIImage { | |
func cropsToSquare() -> UIImage { | |
let refWidth = CGFloat(CGImageGetWidth(self.CGImage)) | |
let refHeight = CGFloat(CGImageGetHeight(self.CGImage)) | |
let cropSize = refWidth > refHeight ? refHeight : refWidth | |
let x = (refWidth - cropSize) / 2.0 | |
let y = (refHeight - cropSize) / 2.0 | |
let cropRect = CGRectMake(x, y, cropSize, cropSize) |
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
#import <Foundation/Foundation.h> | |
typedef void (^DarwinNotificationBlock)(NSString *identifier); | |
@interface Darwin : NSObject | |
+ (Darwin *)sharedInstance; | |
- (void)startListening:(DarwinNotificationBlock)block; | |
- (void)test; |
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
NSNotificationCenter.defaultCenter().addObserverForName(nil, object: nil, queue: nil) { (notification) in | |
NSLog("Notification found with:\r\n name: \(notification.name)\r\n object: \(notification.object)\r\n userInfo: \(notification.userInfo)") | |
} |
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
let className = toString(object.dynamicType).componentsSeparatedByString(".").last! |
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
// Overriding NSLocalizedString to use NSLocalizedStringFromTableInBundle instead | |
#define currentLanguageBundle [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:[[NSLocale preferredLanguages] objectAtIndex:0] ofType:@"lproj"]] | |
#ifdef NSLocalizedString | |
#undef NSLocalizedString | |
#endif | |
#define NSLocalizedString(key, comment) NSLocalizedStringFromTableInBundle(key, nil, currentLanguageBundle, comment) |
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
- (void)downloadFileRetryingNumberOfTimes:(NSUInteger)numberOfTimes | |
success:(void (^)(id responseObject))success | |
failure:(void (^)(NSError *error))failure | |
{ | |
if (numberOfTimes <= 0) { | |
if (failure) { | |
NSError *error = ...; | |
failure(error); | |
} | |
} else { |
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_queue_t mainQueue = dispatch_get_main_queue(); | |
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | |
dispatch_async(backgroundQueue,^{ | |
// Do magical stuff in the background | |
dispatch_async(mainQueue,^{ | |
// Update UI in the main thread |