Skip to content

Instantly share code, notes, and snippets.


Bryan Irace irace

View GitHub Profile
irace / Codable+JSONObjects.swift
Last active Apr 17, 2019
Nearby user discovery through MultipeerConnectivity in Swift
View Codable+JSONObjects.swift
import Foundation
Extensions that allow `JSONEncoder` and `JSONDecoder` to produce/consume dictionaries, instead of simply raw data.
extension JSONEncoder {
func encodeAsJSONObject<T>(_ value: T) throws -> Any where T: Encodable {
return try JSONSerialization.jsonObject(with: try encode(value), options: [])
View ConsoleLogDestination.swift
import Foundation
final class ConsoleLogDestination: LogDestination {
func log(statement: String) {
func error(error: Error) {
View DeduplicatingCollectionViewSelector.swift
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
This class will ensure that we ignore any calls to `selectItemAtIndexPath:animated:scrollPosition:` that are identical
View long-function-bodies.rb
post_install do |installer|
installer.pods_project.targets.each do |target|
if == 'ServiceKit' || == 'SharedUI' || == 'ContactPicker'
target.build_configurations.each do |config|
if == 'Debug'
config.build_settings['OTHER_SWIFT_FLAGS'] = '-Xfrontend -warn-long-function-bodies=100'
config.build_settings['OTHER_SWIFT_FLAGS'] = ''
irace / SearchController.swift
Last active Nov 29, 2017
UISearchController replacement. Relies on a couple of internal categories, helpers, etc.
View SearchController.swift
// SearchController.swift
// Prefer
// Created by Bryan Irace on 5/31/17.
// Copyright © 2017 Prefer. All rights reserved.
import RxSwift
import RxCocoa
irace / Protocols.swift
Last active Apr 1, 2017
Protocol inheritance and associated type specification
View Protocols.swift
This Swift bug seems to be related: Seems as though
the different ways that worked previously might have never actually been intended?
protocol DataVendor {
associatedtype Vended
var data: [Vended]
# A simple script to generate an animated gif from an mp4 file.
# Some notes:
# - To use this you need both ffmpeg and imagemagick installed. You can 'brew install' both of them.
# - Our version of github enterprise has a 10MB size limit per file. Make sure your gifs are below that limit.
# This is based on
View Keychain.swift
import Foundation
import Result
import Security
* A simple wrapper around the Security framework’s keychain functions, providing a Swifty-er API.
typealias KeychainQuery = [String: Any]
struct Keychain {
irace /
Created Sep 19, 2016
Spotify vs. Apple Music
Spotify Apple Music
Amazon Echo integration Offline Apple Watch playback
Smart playlists
View TargetActionSectionFooterTitleView.swift
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.