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 / 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 / IrisSegue.mm
Last active May 16, 2018 19:42
This is a segue that does an iris animation like the iOS camera app. Note: The name cameraIris is private API and might lead to rejection!
@implementation IrisSegue
- (void)perform
{
[self.sourceViewController presentViewController:self.destinationViewController animated:NO completion:^{
// don't ask - it just works with two calls to dispatch_async
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{
NSString* shutterAnimationName = @"cameraIris";
@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];
@michaelochs
michaelochs / lazy-copy-reveal.sh
Created November 23, 2013 13:27
This script copies the Reveal library in your .app file on build time as long as you have Reveal installed and you are not building the configuration 'ReleaseAppStore'. For more info please see my blog post: http://ios-coding.com/improved-way-to-integrate-reveal/
#!/bin/sh
APPBUNDLEPATH="${TARGET_BUILD_DIR}/${EXECUTABLE_NAME}.app/"
REVEALFRAMEWORKPATH="/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib"
if [ -f "${REVEALFRAMEWORKPATH}" ] && [ "${CONFIGURATION}" != "ReleaseAppStore" ]; then
cp "${REVEALFRAMEWORKPATH}" "${APPBUNDLEPATH}"
fi
@michaelochs
michaelochs / gist:7869385
Created December 9, 2013 09:03
NSDateFormatter styles in engl. localization.
Date:
Short: 1/9/07
Medium: Jan 9, 2007
Long: January 9, 2007
Full: Tuesday, January 9, 2007
Time:
Short: 9:42 AM
Medium: 9:42:00 AM
Long: 9:42:00 AM GMT+1
@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