Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Ochs michaelochs

  • Cologne, Germany
View GitHub Profile
View DynamicNSStringEvaluation.m
@interface MyStringProxy : NSProxy
@property (nonatomic) NSString *target;
@end
@implementation MyStringProxy
- (BOOL)respondsToSelector:(SEL)aSelector {
@michaelochs
michaelochs / NSFormattingContextDynamic.m
Created Dec 13, 2016
`NSFormattingContextDynamic` makes a formatter return string proxies that change based on where you but them inside a format string.
View NSFormattingContextDynamic.m
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 / ViewController.m
Created Nov 4, 2016
Test ARC whether it retains self on method execution or not
View ViewController.m
@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 Oct 28, 2016
They way I handled async cell configuration before iOS 10.
View ItemCollectionViewController.m
//
// ItemCollectionViewController.m
// ViewDeckExample
//
// Created by Michael Ochs on 9/17/16.
// Copyright © 2016 ViewDeck. All rights reserved.
//
#import "ItemCollectionViewController.h"
@michaelochs
michaelochs / Podfile
Created Jul 16, 2016
A pod file that doesn't seem to work on CocoaPods 1.0 anymore
View Podfile
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 / NSCharacterSet+Logographic.m
Created Dec 17, 2015
A NSCharacterSet containing (hopefully) all logographic characters from unicode.
View NSCharacterSet+Logographic.m
#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 / ExtendUITableViewDelegate.m
Created Aug 26, 2015
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.
View ExtendUITableViewDelegate.m
@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 / LocalNotifications.m
Last active Aug 29, 2015
Short snipped with an explanation of how your app needs to respond to local notifications.
View LocalNotifications.m
- (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 / post-checkout
Created Mar 12, 2015
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.
View post-checkout
#!/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
View gist:47735d1873d0f598c5ba
http://gsp1.apple.com/pep/gcc - Returns the current country code - Probably based on the IP address?