Skip to content

Instantly share code, notes, and snippets.

matej / CALayer+MBAnimationPersistence.h
Last active Jan 15, 2021
Persists (pauses) layer animations (including UIView animation generated animations) when the application enters into background and restores (resumes) animations from where they left off upon returning from background.
View CALayer+MBAnimationPersistence.h
// CALayer+MBAnimationPersistence.h
// Created by Matej Bukovinski on 19. 03. 14.
// Copyright (c) 2014 Matej Bukovinski. All rights reserved.
#import <QuartzCore/QuartzCore.h>
steipete / PSPDFModernizer.c
Last active Mar 9, 2017
Retrofitting containsString: on iOS 7
View PSPDFModernizer.c
#import <Foundation/Foundation.h>
@interface NSString (PSPDFModernizer)
// Added in iOS 8, retrofitted for iOS 7
- (BOOL)containsString:(NSString *)aString;
mackuba /
Last active Dec 28, 2020
New stuff from WWDC 2015

Here's my own list of the interesting stuff announced during this year's WWDC, collected from the keynotes, various Apple docs, blog posts and tweets.

If you're planning to watch the videos, I really recommend this Mac app that helps you download and watch them:

OS X El Capitan

  • split view - two apps side by side on full screen
sakrist /
Last active Jan 18, 2022
GMP and MPFR compile for iOS
# Filename:
# Created by Volodymyr Boichentsov on 18/09/2015.
# Copyright © 2015 3D4Medical. All rights reserved.
# Property of 3D4Medical.
#-emit-obj -fembed-bitcode -disable-llvm-optzns -O3
plumhead / StringSize.swift
Created Sep 15, 2015
String extension to find the layout size of a String with specified attributes.
View StringSize.swift
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)
k06a /
Last active May 14, 2021
Git remove some dirs
# Fetch
git clone reponame
for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done
# Analyze
curl > && sudo python && rm
sudo pip install git-fat
git fat -a find 1000000
git ls-tree -r -t -l --full-name HEAD | sort -n -k 4
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active Jan 16, 2022
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
View InteractiveTransitionCollectionViewDeselection.m
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
tclementdev /
Last active Jan 19, 2022
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

joseph-elmallah / URL+UIResponder.swift
Created Dec 9, 2018
A decoupled way to propagate URL opening in an iOS app over the Responder chain
View URL+UIResponder.swift
/// Conforming to this protocol allows for URL handling
protocol URLHandler {
/// Handle a URL
/// - Parameter url: The propagated url
/// - Returns: The handled status
func handleURL(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey : Any], completionHandler completion: ((Bool) -> Void)?)
// MARK: - Error Propagation
View Accessible.swift
protocol Accessible {
func generateAccessibilityIdentifiers()
extension Accessible {
func generateAccessibilityIdentifiers() {
let mirror = Mirror(reflecting: self)