Skip to content

Instantly share code, notes, and snippets.

View diederikh's full-sized avatar

Diederik Hoogenboom diederikh

View GitHub Profile
@diederikh
diederikh / gist:3181541
Created July 26, 2012 11:20
31th Jan + 1 Month
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *comp = [NSDateComponents new];
comp.day = 31;
comp.month = 1;
comp.year = 2012;
NSDateComponents *addMonthComp = [NSDateComponents new];
addMonthComp.month = 1;
NSLog(@"31th Jan + 1 month: %@",[cal dateByAddingComponents:addMonthComp toDate:[cal dateFromComponents:comp] options:0]);
@diederikh
diederikh / gist:4761140
Created February 12, 2013 09:19
.gitignore
.DS_Store
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
xcuserdata/
project.xcworkspace/
.svn
@diederikh
diederikh / gist:3dd2686250ec899be7da
Created September 26, 2013 07:09
Nice Table view cell animation: Cells flying on from the left (3D)
//This function is where all the magic happens
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
//1. Setup the CATransform3D structure
CATransform3D rotation;
rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
rotation.m34 = 1.0/ -600;
@diederikh
diederikh / LBHView.h
Created May 4, 2014 09:51
A terrible, terrible hack to toggle AppKit's destruction of layer modifications.
#import <Cocoa/Cocoa.h>
@interface LBHView : NSView
/// This property controls whether the view can indirectly control its
/// backing layer's properties, specifically the following:
/// `affineTransform`
/// `anchorPoint`
///
/// These properties cannot be modified on the layer during the time that
// Fill this out with whatever you want. Use the same string
// and algorithm to scramble the files on the server.
static unsigned char secretString[SECRET_STRING_LENGTH];
- (NSData *)scrambleOrDescrambleData:(NSData*)input
{
unsigned char *outputBytes = malloc(input.length);
memcpy(outputBytes, input.bytes, input.length);
for (int i = 0; i < input.length; i++)
{
@diederikh
diederikh / gist:c576c2eb13347d302de6
Created May 17, 2014 22:36
Log all Objective-C method calls
2 options:
1. set the environment variable NSObjCMessageLoggingEnabled to YES. This will write a log of all message sends in the folder /tmp/msgSends-xxx.
2. #import <objc/runtime.h>
call (void)instrumentObjcMessageSends(YES); to enable
call (void)instrumentObjcMessageSends(NO); to disable. All output is logged to /tmp/msgSends...
@diederikh
diederikh / gist:0c2c7247b57359389637
Created May 22, 2014 19:21
Format currency into a string using locale
NSDecimalNumber *price = [NSDecimalNumber decimalNumberWithString:@"1.99"];
NSLocale *priceLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"be_BE"] autorelease]; // get the locale from your SKProduct
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormatter setLocale:priceLocale];
NSString *currencyString = [currencyFormatter currencySymbol];
NSString *format = [currencyFormatter positiveFormat];
format = [format stringByReplacingOccurrencesOfString:@"¤" withString:currencyString];
// ¤ is a placeholder for the currency symbol
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
@diederikh
diederikh / gist:7c9862750040951497ce
Last active April 17, 2017 00:45
Transition to view controller within container view (called in performForSegue:)
- (void)switchToViewController:(UIViewController *)viewController
{
UIViewController *currentViewController = self.childViewControllers[0];
[self addChildViewController:viewController];
[self transitionFromViewController:currentViewController toViewController:viewController duration:0.2 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{}
completion:^(BOOL finished) {
[currentViewController removeFromParentViewController];
[self.containerView addSubview:viewController.view];
}];
}
@diederikh
diederikh / gist:a510b99981d5d1c2857f
Created January 5, 2015 10:00
dequeueUsingReuseID in Swift
import UIKit
class ExpenseListViewController : UITableViewController, UITableViewDataSource, UITableViewDelegate {
struct TableViewCellIdentifiers {
static let BasicCell = "BasicCell"
}
// MARK: - UITableViewDataSource