Skip to content

Instantly share code, notes, and snippets.

View irace's full-sized avatar

Bryan Irace irace

View GitHub Profile
import Foundation
/**
Coordinators are a design pattern that encourages decoupling view controllers such that they know as little as possible
about how they are presented, and don’t directly manipulate data or present other view controllers. Coordinators can be
“nested” such that child coordinators encapsulate different flows and present any from becoming too large.
- https://vimeo.com/144116310
- http://khanlou.com/2015/10/coordinators-redux/
- http://khanlou.com/2015/01/the-coordinator/
import UIKit
/**
A drop-in replacement for the `UITableView`’s default section footer title, adding support for inline links. This class
will call the same, single target/action pair for *all* inline links, regardless of what their `NSLinkAttributeName`
values are. If you need to support multiple different inline links, this class is not for you.
Instead of implementing `tableView(tableView:titleForFooterInSection:)` and returning a string, implement
`tableView(tableView:, viewForFooterInSection section: Int)` and return an instance of this class.
@irace
irace / SearchController.swift
Last active November 29, 2017 19:35
UISearchController replacement. Relies on a couple of internal categories, helpers, etc.
//
// SearchController.swift
// Prefer
//
// Created by Bryan Irace on 5/31/17.
// Copyright © 2017 Prefer. All rights reserved.
//
import RxSwift
import RxCocoa
@irace
irace / CenteringView.swift
Last active November 29, 2017 19:31
I’m building a complex new app entirely with programmatic Auto Layout. It only supports iOS 9 so that means `UIStackView` and `NSLayoutAnchor` exclusively. These two classes have been very handy thus far, in the spirit of composition over inheritance.
final class CenteringView: UIView {
// MARK: - Initialization
init(contentView: UIView) {
super.init(frame: .zero)
addSubview(contentView)
contentView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activateConstraints([
import UIKit
/**
Enables smooth collection view selection by de-duplicating calls to `selectItemAtIndexPath:animated:scrollPosition:`
If `selectItemAtIndexPath:animated:scrollPosition:` is being driven off of something like `scrollViewDidScroll:`
delegate calls, we’d likely be invoking the former needlessly, with the same index path. This can result in jerky
scrolling.
This class will ensure that we ignore any calls to `selectItemAtIndexPath:animated:scrollPosition:` that are identical
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'ServiceKit' || target.name == 'SharedUI' || target.name == 'ContactPicker'
target.build_configurations.each do |config|
if config.name == 'Debug'
config.build_settings['OTHER_SWIFT_FLAGS'] = '-Xfrontend -warn-long-function-bodies=100'
else
config.build_settings['OTHER_SWIFT_FLAGS'] = ''
end
end
@irace
irace / Stopwatch.swift
Created October 4, 2014 20:55
A simple stopwatch in Swift
import Foundation
/**
* A really simple timer that I didn't want to call `Timer` because timer means something else in Foundation.
*/
@objc class Stopwatch: NSObject {
private var startTime: NSDate?
var isRunning: Bool {
return startTime != nil
@irace
irace / gist:3506126
Created August 29, 2012 02:12
Why develop a native mobile application?

Published May 17, 2011 based on experiences building GS Research for iPad. Updates will be additive as the original article will be kept intact for posterity.

UPDATE (9/22/2012): Facebook developer Tobie Langel has posted some interesting feedback to a W3C mailing list in the aftermath of rewriting Facebook's failed web-based iOS application.

UPDATE 2 (11/28/2012): And now my app (Tumblr) is fully native as well.


Audience

Interested in building a mobile application but not sure where to start? There are a dizzying number of frameworks and platforms all currently vying to be your answer. In order to decide which is right for you, it’s important to understand the pros and cons of the different mobile development and deployment strategies available today.

@irace
irace / Protocols.swift
Last active April 1, 2017 20:33
Protocol inheritance and associated type specification
/*
This Swift bug seems to be related: https://bugs.swift.org/browse/SR-2235. Seems as though
the different ways that worked previously might have never actually been intended?
*/
protocol DataVendor {
associatedtype Vended
var data: [Vended]
@irace
irace / gist:927f843cb0f683a7f2c2
Created August 13, 2014 20:03
New iOS 8 APIs don't allow you to use a custom presentation controller for compact devices, in conjunction with a popover on "normal" size class devices
//
// ViewController.m
// PopoverPresentationControllerExample
//
// Created by Bryan Irace on 8/8/14.
// Copyright (c) 2014 Bryan Irace. All rights reserved.
//
#import "CustomCompactPresentationController.h"
#import "ViewController.h"