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 / 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 / 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 / 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 / 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 / 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
http://gsp1.apple.com/pep/gcc - Returns the current country code - Probably based on the IP address?