Skip to content

Instantly share code, notes, and snippets.

View myell0w's full-sized avatar
🙌

Matthias Tretter myell0w

🙌
View GitHub Profile
@jazzychad
jazzychad / SPVMainViewController.m
Created December 8, 2013 22:04
example of transferring velocity of UIPanGestureRecoginizer to a UIView spring animation.
#import "SPVMainViewController.h"
@implementation SPVMainViewController
{
UIView *_weightView;
UIPanGestureRecognizer *_recog;
}
- (void)viewDidLoad
{
/**
Provides the ability to verify key paths at compile time.
If "keyPath" does not exist, a compile-time error will be generated.
Example:
// Verifies "isFinished" exists on "operation".
NSString *key = SQKeyPath(operation, isFinished);
// Verifies "isFinished" exists on self.
@interstateone
interstateone / partial.m
Last active August 29, 2015 14:01
A little demo of partial application for variadic blocks
#import <Foundation/Foundation.h>
#define apply(block, a) (^{ \
switch (a.count) { \
case 1: return block(a[0], nil); \
case 2: return block(a[0], a[1], nil); \
case 3: return block(a[0], a[1], a[2], nil); \
case 4: return block(a[0], a[1], a[2], a[3], nil); \
case 5: return block(a[0], a[1], a[2], a[3], a[4], nil); \
@nicklockwood
nicklockwood / Deprecated.md
Last active March 28, 2022 08:16
Writing Objective-C framework code that works on multiple OS versions AND can be compiled using multiple SDK versions without warnings can be a PITA. Here's my approach:

Suppose we want to add support for a new iOS 8 API in our framework that replaces an older iOS 7 API. There are a few problems we might face:

  1. The new API will crash if we call it on iOS 7
  2. The new API won't compile if we build it using the iOS 7 SDK
  3. The old API will raise a deprecation warning if built with a deployment target of iOS 8 and up

These three problems require three different technical solutions:

  1. We can avoid calling the new API on an old OS version by using runtime detection (e.g. respondsToSelector:)
  2. We can avoid compiling new APIs on old SDKs using the __IPHONE_OS_VERSION_MAX_ALLOWED macro
@martinhering
martinhering / gist:068edb5908fe04c677e6
Last active August 29, 2015 14:04
Managing scrollview.contentInset adjustment manually
- (void) setScrollView:(UIScrollView*)scrollView contentInsets:(UIEdgeInsets)edgeInsets byAdjustingForStandardBars:(BOOL)adjustStandardBars
{
if (adjustStandardBars)
{
UINavigationController* navController = self.navigationController;
if (navController)
{
CGRect navBarFrame = self.navigationController.navigationBar.frame;
edgeInsets.top += CGRectGetMinY(navBarFrame); // statusbar
@Kapeli
Kapeli / NSCrapField.m
Last active March 9, 2020 18:57
Yosemite NSSearchField Fixes
// 1. Disable centered look & animation:
// 1.1. Subclass NSSearchFieldCell and add:
- (BOOL)isCenteredLook
{
return NO;
}
// 1.2. Subclass NSSearchField and add:
@zwaldowski
zwaldowski / UIFontDescriptor+DynamicType.m
Created November 9, 2014 22:06
Dynamic Type with Weight-Matching
@implementation UIFontDescriptor (DZWDynamicType)
+ (instancetype)dzw_preferredFontDescriptorWithTextStyle:(NSString *)style {
return [[self preferredFontDescriptorWithTextStyle:style] dzw_fontDescriptorWithMatchingFamily:@"Avenir Next"];
}
- (instancetype)dzw_fontDescriptorWithMatchingFamily:(NSString *)family {
NSMutableDictionary *attributes = [self.fontAttributes mutableCopy];
[attributes removeObjectForKey:UIFontDescriptorTextStyleAttribute];
UIFontDescriptor *newDesc = (__bridge_transfer UIFontDescriptor *)CTFontDescriptorCreateCopyWithFamily((__bridge CTFontDescriptorRef)self, (__bridge CFStringRef)family);
@bjhomer
bjhomer / .gitconfig
Created March 13, 2015 18:15
A git alias to delete branches whose remote tracking branches are gone
# Drop this into your ~/.gitconfig
[alias]
delete-merged = !bash -c '\
REMOTE=$1 && \
REMOTE=${REMOTE:="origin"} && \
echo "Fetching $REMOTE" && \
git fetch $REMOTE --prune && \
git branch -vv | grep "gone]" | awk \"{ print \\$1 }\" | xargs git branch -d' -
//some time, frc section may be need section offset
@objc public protocol MFetchedResultsControllerOffsetSectionDelegate{
func offsetSection() -> Int
}
class MFetchedResultsController: NSFetchedResultsController, NSFetchedResultsControllerDelegate {
weak var viewController: UIViewController? //UITableViewController UICollectionViewController
weak var scrollView: UIScrollView? //TableView CollectionView
weak var offsetSectionDelegate: MFetchedResultsControllerOffsetSectionDelegate?
@timonus
timonus / UIWindow+AppSwitchScrollStopper.h
Last active January 6, 2017 19:01
AppSwitchScrollStopper
// UIWindow+AppSwitchScrollStopper.h
// Created by Tim Johnsen on 3/27/16.
#import <UIKit/UIKit.h>
@interface UIWindow (AppSwitchScrollStopper)
/// Call this early on in your app's lifecycle to avoid
/// scroll-related flashing when your app resumes from the background
- (void)installAppSwitchScrollStopper;