Skip to content

Instantly share code, notes, and snippets.

tapi / wwdc2014
Created Jul 16, 2019 — forked from phnessu4/wwdc2014
wwdc 2014 sessions and pdf
View wwdc2014
tapi / Pairwise+Sequence.swift
Created Dec 5, 2017
Swift 4 - Pairwise Sequence
View Pairwise+Sequence.swift
public struct PairwiseIterator<T>: IteratorProtocol {
private var iterator: AnyIterator<T>
private var lastElement: T?
public init(_ iterator: AnyIterator<T>) {
self.iterator = iterator
self.lastElement =
tapi / UICollectionView+Registration.swift
Created Apr 4, 2016
Typed UITableView & UICollectionView Dequeuing in Swift
View UICollectionView+Registration.swift
import UIKit
extension UICollectionReusableView {
/// The default implementation of `defaultIdentifier()` uses `NSStringFromClass(class)` rather than `String(class)` so that the module name is includded.
/// The hope being that this makes collisions unlikely making it unnnecessary to provide your own implementations.
public class func defaultIdentifier() -> String {
return NSStringFromClass(self)
tapi / ReferenceTypes.swift
Created Nov 26, 2015
Test case demonstrating relationship clobbering in ObjectMapper 1.0
View ReferenceTypes.swift
import Foundation
import ObjectMapper
class Person: Mappable {
var name: String?
var spouse: Person?
required init?(_ map: Map) {
tapi / error extension
Created Mar 27, 2015
Wouldn't this work instead of a nil default?
View error extension
extension NSError{
class func
myParseError(description:String?="Parse failed.") -> NSError {
let info = [NSLocalizedDescriptionKey: description]
return self(
tapi / GroupBy.swift
Created Feb 6, 2015
A generic groupby function that should work similarily to ruby's
View GroupBy.swift
Group all items in a collection according to the value returned by a block.
:param: collection The collection whose items you want to group.
:param: groupBlock A block that returns a key for that value to be grouped by.
:returns: Returns a dictionary whose keys are the values returned by the groupBlock.
func groupBy<V, K : protocol<Hashable, Equatable>, C : _ExtensibleCollectionType where C.Generator.Element == V>(collection: C, groupBlock: (V) -> K) -> [K: [V]] {
typealias ValueGroup = [V]
tapi / BookExample.swift
Created Jun 4, 2014
Generic types broken into separate lines
View BookExample.swift
func anyCommonElements <T, U where T: Sequence, U: Sequence, T.GeneratorType.Element: Equatable, T.GeneratorType.Element == U.GeneratorType.Element> (lhs: T, rhs: U) -> Bool {
for lhsItem in lhs {
for rhsItem in rhs {
if lhsItem == rhsItem {
return true
return false
View gist:9883933
### Keybase proof
I hereby claim:
* I am tapi on github.
* I am tapi ( on keybase.
* I have a public key whose fingerprint is B8A2 FE8D A75F 3FD8 9114 77D5 E7E6 6A04 5D6C 1382
To claim this, I am signing this object:
tapi / gist:9236422
Created Feb 26, 2014
This is the funkiest assignment syntax I have ever seen used in Objective-C
View gist:9236422
_imageView = ({
UIImageView *imageView = [[UIImageView alloc] init];
imageView.contentMode = UIViewContentModeScaleAspectFill;
[self.scrollView addSubview:imageView];
tapi / pageViewGestures.m
Created Aug 14, 2013
A little had to get at the gesture recognizers of a UIPageviewControllers paging view
View pageViewGestures.m
- (void)didMoveToParentViewController:(UIViewController *)parent
[super didMoveToParentViewController:parent];
if ([parent isKindOfClass:[UIPageViewController class]]) {
UIScrollView *scrollView;
for (UIView *view in parent.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
scrollView = (UIScrollView *)view;