Skip to content

Instantly share code, notes, and snippets.

Sam Soffes soffes

View GitHub Profile
View Readme.markdown

CFRunLoopSource is cool. It lets you build behavior similar to the mechanisms that drive setNeedsLayout and setNeedsDisplay in UIKit.

I found myself in need of something like this a couple of times. It's great to know that no matter how many times I say I need to update something, I will get a single callback at the end of the run loop that gives me a chance to perform my work.

Here is a little Swift wrapper that makes the API easier to deal with.

Updated for Swift 4

soffes / Vagrantfile
Last active Jul 19, 2017
Vagrantfile for working with Swift
View Vagrantfile
Vagrant.configure(2) do |config| = "boxcutter/ubuntu1610"
config.ssh.pty = true
config.vm.provision "shell", inline: <<-SHELL
su vagrant
sudo apt-get -y update
sudo apt-get install -y git python-dev libcurl3 clang
git clone ~/.swiftenv
echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile
soffes / Rakefile
Last active Feb 25, 2019
Programmatically build and sign a Developer ID macOS app
View Rakefile
APP_NAME = 'My App'
desc 'Create a beta build'
task :build do
# Ensure clean git state
unless system 'git diff-index --quiet HEAD --'
abort 'Failed. You have uncommitted changes.'
soffes / BaseTextStorage.swift
Last active Feb 24, 2019
Fast, concrete text storage intended to be subclassed.
View BaseTextStorage.swift
import UIKit
/// Fast, concrete text storage intended to be subclassed.
class BaseTextStorage: NSTextStorage {
// MARK: - Properties
private let storage = NSMutableAttributedString()
// MARK: - NSTextStorage
soffes / WebCredential.swift
Last active Apr 18, 2019
Easily access Shared Web Credentials
View WebCredential.swift
import Foundation
import Security
struct SharedWebCredentials {
// MARK: - Types
struct Credential {
let domain: String
let account: String
soffes / UISplitViewController+Soffes.swift
Created Jun 8, 2016
Easily access master and detail view controllers on UISplitViewController
View UISplitViewController+Soffes.swift
import UIKit
extension UISplitViewController {
convenience init(masterViewController: UIViewController, detailViewController: UIViewController) {
viewControllers = [masterViewController, detailViewController]
var masterViewController: UIViewController? {
return viewControllers.first
View UIColor+Desaturated.swift
import UIKit
extension UIColor {
var desaturated: UIColor {
var hue: CGFloat = 0
var brightness: CGFloat = 0
var alpha: CGFloat = 0
getHue(&hue, saturation: nil, brightness: &brightness, alpha: &alpha)
View gist:3fa2f8fa7ee3bb14225d738aaa42918b
$ git clone
$ cd ISO8601
$ pod trunk push --verbose
[!] Found podspec `ISO8601.podspec`
Updating spec repo `master`
Validating podspec
ISO8601 (0.5.2) - Analyzing on OS X platform.
soffes / SectionHeaderView.swift
Created Jun 3, 2016
Plain table view section header replacement
View SectionHeaderView.swift
import UIKit
class SectionHeaderView: UIView {
// MARK: - Properties
let textLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = .boldSystemFontOfSize(17)
soffes / NavigationBar.swift
Created Jun 3, 2016
Change navigation bar border color
View NavigationBar.swift
import UIKit
class NavigationBar: UINavigationBar {
// MARK: - Properties
var borderColor: UIColor? {
set {
borderView.backgroundColor = newValue
You can’t perform that action at this time.