Skip to content

Instantly share code, notes, and snippets.

View irace's full-sized avatar

Bryan Irace irace

View GitHub Profile
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 / TabComponent.swift
Last active December 22, 2020 15:38
Easily roll your own `UITabBarController` alternatives. Here’s all the logic you need without assuming anything about your UI.
/**
* A class that can be part of a tabbed navigational interface (expected to be a `UIViewController` but can also be a
* coordinator that proxies through to an underlying controller).
*/
public protocol TabComponent {
/// The tab metadata
var tabItem: TabItem { get }
var viewController: UIViewController { get }
}
@irace
irace / Optional+Empty.swift
Last active June 16, 2016 16:17
`UITextView` should really just have this by default.
protocol TextContaining {
var isEmpty: Bool { get }
}
extension String: TextContaining {
}
extension Optional where Wrapped: TextContaining {
var isEmpty: Bool {
switch self {
@irace
irace / Protocol inheritance.swift
Created May 11, 2016 14:24
Works in a playground, does not work in a project file as of Xcode 7.3.1
protocol Foo {
}
extension Foo {
func bar() -> Self { return self }
}
extension NSObject: Foo {}
let view = UIView().bar() // Value of type `UIView` has no member `bar`
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/
@irace
irace / sound.md
Last active March 23, 2016 17:29
Ideal iOS notifications/sounds setup
  1. When volume switch is On, phone both makes noise and vibrates.

  2. When volume switch is Off, phone does not make noise or vibrate.

  3. Calls should make noise/vibrate in extenuating cirumstances, e.g. a call from a favorite or two calls within three minutes.

Vibrate on Silent accomplishes 1 and 2, but prevents 3 from occurring.

3 could be accomplished by ignoring the volume switch altogether and using Do Not Disturb to solely determine whether my phone is silent or not. In this case, I would have DND turned on almost all of the time. The problem with this is that when the phone is unlocked/in use, notifications will either A) not be shown at all or B) will cause noise/vibration.

@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([
@irace
irace / ViewControllerSequence.swift
Created January 8, 2016 21:58
Trying to model a sequence of view controllers.
struct ViewControllerSequence {
typealias ViewControllerProducer = Void -> UIViewController
private var storage = TypeDictionary<ViewControllerProducer>()
private var producers: [ViewControllerProducer]
init(_ producers: [ViewControllerProducer]) {
self.producers = producers
}
@irace
irace / Validate.swift
Created December 2, 2015 04:30
Possible to write a function that can return any Instance conforming to Validator where ValidatedType == String?
protocol Validator {
typealias ValidatedType
func isValid(object: ValidatedType) -> Bool
}
struct NonEmptyValidator: Validator {
func isValid(object: String) -> Bool {
return object.isEmpty
}
@irace
irace / checklist.md
Created October 29, 2015 21:16
iOS development checklist

Qualifies

Already had

  • Accessibility
  • Handoff
  • Safari Shared Credentials
  • iCloud Keychain
  • iPad Multitasking
  • State Restoration