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 / DynamicNSStringEvaluation.m
Last active February 6, 2022 14:47
As a follow up for https://gist.github.com/michaelochs/f106b5c42aafe6bed74ac5dab82281c4 this is what's going on under the hood!
@interface MyStringProxy : NSProxy
@property (nonatomic) NSString *target;
@end
@implementation MyStringProxy
- (BOOL)respondsToSelector:(SEL)aSelector {
@michaelochs
michaelochs / NSFormattingContextDynamic.m
Created December 13, 2016 15:37
`NSFormattingContextDynamic` makes a formatter return string proxies that change based on where you but them inside a format string.
NSDate *date = [NSDate new];
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"nl_NL"];
dateFormatter.dateStyle = NSDateFormatterFullStyle;
dateFormatter.formattingContext = NSFormattingContextDynamic; // this is the important setting
NSString *dateString = [dateFormatter stringFromDate:date];
NSString *s1 = [NSString stringWithFormat:@"Foo %@", dateString]; // "Foo dinsdag 13 december 2016"
@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 / ViewController.m
Created November 4, 2016 18:36
Test ARC whether it retains self on method execution or not
@interface MyObject : NSObject
@end
@implementation MyObject
- (void)doSomething {
for (int i = 0; i < 1000; i++) {
[self print:i];
usleep(100);
}
@michaelochs
michaelochs / ItemCollectionViewController.m
Created October 28, 2016 14:44
They way I handled async cell configuration before iOS 10.
//
// ItemCollectionViewController.m
// ViewDeckExample
//
// Created by Michael Ochs on 9/17/16.
// Copyright © 2016 ViewDeck. All rights reserved.
//
#import "ItemCollectionViewController.h"
@michaelochs
michaelochs / Podfile
Created July 16, 2016 13:27
A pod file that doesn't seem to work on CocoaPods 1.0 anymore
use_frameworks!
pod 'CocoaLumberjack', '~> 2.0'
pod 'HRSCustomErrorHandling', :git => 'https://github.com/Hotel-Reservation-Service/HRSCustomErrorHandling.git', :commit => 'c4aa9fa7f670bb9b6e737893d94031bbbf335d29' #'~> 0.2'
pod 'Aspects', '~> 1.4'
pod 'BCFoundation', :path => '../../BCComponents'
pod 'BCInterface', :path => '../../BCComponents'
pod 'TFFoundation', :path => '../TFFoundation'
@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 / .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 / 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;
}