Skip to content

Instantly share code, notes, and snippets.

@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active January 15, 2023 13:03
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// 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) {
@sakrist
sakrist / build_gmp.sh
Last active November 9, 2022 06:27
GMP and MPFR compile for iOS
#!/bin/bash
#===============================================================================
# Filename: build_gmp.sh
# 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
plumhead / StringSize.swift
Created September 15, 2015 13:34
String extension to find the layout size of a String with specified attributes.
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()
layout.addTextContainer(container)
storage.addLayoutManager(layout)
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)
@mackuba
mackuba / wwdc15.md
Last active August 6, 2022 17:28
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: https://github.com/insidegui/WWDC.

OS X El Capitan

http://www.apple.com/osx/elcapitan-preview/

  • split view - two apps side by side on full screen
// TaskMeeting
// (c) 2022, Nikolai Ruhe
/// A type that synchronizes progress of two tasks.
public final actor TaskMeeting: Sendable {
private var completion: CheckedContinuation<Void, Error>? = nil
/// This method synchronizes two tasks so that both perform the closure at
/// the same time. Both tasks need to call `rendezvous`.
///
@joseph-elmallah
joseph-elmallah / URL+UIResponder.swift
Created December 9, 2018 20:39
A decoupled way to propagate URL opening in an iOS app over the Responder chain
/// 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
@k06a
k06a / erase-git.sh
Last active May 14, 2021 03:14
Git remove some dirs
# Fetch
git clone https://github.com/username/reponame reponame
for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done
# Analyze
curl https://bootstrap.pypa.io/get-pip.py > get-pip.py && sudo python get-pip.py && rm get-pip.py
sudo pip install git-fat
git fat -a find 1000000
git ls-tree -r -t -l --full-name HEAD | sort -n -k 4
@steipete
steipete / PSPDFModernizer.c
Last active March 9, 2017 08:26
Retrofitting containsString: on iOS 7
#import <Foundation/Foundation.h>
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
@interface NSString (PSPDFModernizer)
// Added in iOS 8, retrofitted for iOS 7
- (BOOL)containsString:(NSString *)aString;
@end