Skip to content

Instantly share code, notes, and snippets.

View pala's full-sized avatar
🏠
Working from home

Tao Zhang pala

🏠
Working from home
View GitHub Profile
@pala
pala / TZReceptionist.h
Created February 10, 2014 19:23
Receptionist Pattern
#import <Foundation/Foundation.h>
typedef void (^RCTaskBlock)(NSString *keyPath, id object, NSDictionary *change);
@interface TZReceptionist : NSObject
+ (id)receptionistForKeyPath:(NSString *)path
object:(id)obj
queue:(NSOperationQueue *)queue
task:(RCTaskBlock)task;
@end
@pala
pala / Singleton.swift
Last active August 29, 2015 14:02
Singleton in Swift
public class var sharedConfiguration: AppConfiguration {
struct Singleton {
static let sharedAppConfiguration = AppConfiguration()
}
return Singleton.sharedAppConfiguration
}
// Checkout Lister: A Productivity App Built in Swift by Apple
@pala
pala / emptyImage.swift
Created May 24, 2015 05:40
UIImage extension
// https://twitter.com/dwineman/status/601853359839006721
// Default arguments are expressions, not constants, evaluated only when necessary.
extension UIImage {
static func emptyImage(size: CGSize, scale: CGFloat = UIScreen.mainScreen().scale) -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, scale)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}