Skip to content

Instantly share code, notes, and snippets.

View michaelochs's full-sized avatar

Michael Ochs michaelochs

  • Cologne, Germany
View GitHub Profile
@michaelochs
michaelochs / ExtendUITableViewDelegate.m
Created August 26, 2015 14:18
An example of how we at HRS expand the `UITableViewDelegate` protocol to trigger custom actions from a cell and communicate them to the table view's delegate.
@protocol HRSStepperTableViewCellDelegate<UITableViewDelegate>
- (void)tableView:(UITableView *)tableView didChangeStepperValue:(UIStepper *)stepper forRowWithIndexPath:(NSIndexPath *)indexPath;
@end
@implementation HRSStepperTableViewCell
- (UITableView *)tableView {
UIView *superview = self.superview;
while (superview != nil && [superview isKindOfClass:[UITableView class]] == NO) {
@michaelochs
michaelochs / MyViewController-ModelHandling.m
Last active August 29, 2015 14:02
A template for a custom UIViewController with proper model handling. See http://www.ios-coding.com/blog/2014/06/22/model-handling-in-uiviewcontroller/
// Copyright 2014 bitecode, Michael Ochs
//
// See http://www.ios-coding.com/blog/2014/06/22/model-handling-in-uiviewcontroller/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
http://gsp1.apple.com/pep/gcc - Returns the current country code - Probably based on the IP address?
@michaelochs
michaelochs / post-checkout
Created March 12, 2015 07:50
A git post checkout hook that ensures your pods are up to date. If there are no changes in the pods environment, this script does nothing.
#!/bin/sh
diff "Podfile.lock" "Pods/Manifest.lock" > /dev/null
if [[ $? != 0 ]] ; then
echo 'CocoaPods needs some more clean up...'
echo 'Quit iOS simulator...'
osascript -e 'tell app "iPhone Simulator" to quit'
echo 'Quit Xcode...'
osascript -e 'tell app "Xcode" to quit'
pod install
@michaelochs
michaelochs / LocalNotifications.m
Last active August 29, 2015 14:23
Short snipped with an explanation of how your app needs to respond to local notifications.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
// the user opened your app by tapping either the notification banner, the notification
// center entry or the open action in the alert view of the notification while your app
// was not running / suspended.
// This is where you want to react to the user's action!
}
}
@michaelochs
michaelochs / date formatter
Last active December 17, 2015 06:39
Shared Dateformatter for performance optimization
+ (instancetype)uiDateFormatter
{
static NSDateFormatter* uiDateFormatter = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
uiDateFormatter = [[NSDateFormatter alloc] init];
uiDateFormatter.dateStyle = NSDateFormatterFullStyle;
uiDateFormatter.timeStyle = NSDateFormatterNoStyle;
});
return uiDateFormatter;
@michaelochs
michaelochs / NSCharacterSet+Logographic.m
Created December 17, 2015 12:32
A NSCharacterSet containing (hopefully) all logographic characters from unicode.
#define CharacterRange(__from__, __to__) NSMakeRange(__from__, __to__ - __from__ + 1)
@implementation NSCharacterSet (HRSCharacterSet)
+ (instancetype)logographicCharacterSet
{
NSRange ranges[] = {
CharacterRange(0x2E80, 0x2EFF), // CJK Radicals Supplement
CharacterRange(0x2F00, 0x2FDF), // Kangxi Radicals
CharacterRange(0x3300, 0x33FF), // CJK Compatibility
@michaelochs
michaelochs / NSNumber+Subscripting.m
Created July 11, 2013 11:59
NSIndexSet subscripting support
@implementation NSNumber (Subscripting)
// call it like this: [@0:1];
- (NSIndexSet*):(NSUInteger)length
{
return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange([self unsignedIntegerValue], length)];
}
@end
@michaelochs
michaelochs / UINavigationBar+iOS7Tint.m
Created September 20, 2013 08:56
Adds -[UINavigationBar setBarTintColor:] and -[UINavigationBar barTintColor] on iOS6 so that you don't have to check for that all the time.
#import <objc/runtime.h>
@implementation UINavigationBar (iOS7Tint)
static void setter(UINavigationBar *self, SEL _cmd, UIColor *tintColor)
{
self.tintColor = tintColor;
}
@michaelochs
michaelochs / .lldbinit
Created November 23, 2013 13:24
If you add this content to your ~/.lldbinit you can launch the Reveal library from within your debugger as long as you have the library added to your app bundle. For more info please see my blog post: http://ios-coding.com/improved-way-to-integrate-reveal/
command alias reveal_load expr (void*)dlopen([(NSString*)[(NSBundle*)[NSBundle mainBundle] pathForResource:@"libReveal" ofType:@"dylib"] cStringUsingEncoding:0x4], 0x2);
command alias reveal_start expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil];
command alias reveal_stop expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStop" object:nil];