Skip to content

Instantly share code, notes, and snippets.

Sam Soffes soffes

Block or report user

Report or block soffes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@soffes
soffes / highlight.swift
Last active May 20, 2019 — forked from orta/highlight.swift
Swift implementation to highlight Cocoa UI elements (http://stackoverflow.com/a/25984748/316803)
View highlight.swift
// Taken from:
// https://gist.github.com/joelcox/28de2f0cb21ea47bd789
NSColor.selectedMenuItemColor.set()
NSBezierPath(rect: rect).fill()
if rect.height > 1 {
let currentControlTint = NSColor.currentControlTint
let startingAlpha: CGFloat = currentControlTint == .blueControlTint ? 0.16 : 0.09
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
soffes / Vagrantfile
Last active Jul 19, 2017
Vagrantfile for working with Swift
View Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "boxcutter/ubuntu1610"
config.ssh.pty = true
config.vm.provision "shell", inline: <<-SHELL
su vagrant
cd
sudo apt-get -y update
sudo apt-get install -y git python-dev libcurl3 clang
git clone https://github.com/kylef/swiftenv.git ~/.swiftenv
echo 'export SWIFTENV_ROOT="$HOME/.swiftenv"' >> ~/.bash_profile
@soffes
soffes / Rakefile
Last active May 12, 2019
Programmatically build and sign a Developer ID macOS app
View Rakefile
TEAM_ID = 'XXXXXXXXXX'
APP_NAME = 'My App'
SCHEME_NAME = APP_NAME
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.'
end
@soffes
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
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
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) {
self.init()
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 https://github.com/soffes/ISO8601
$ 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.
Preparing
@soffes
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)
You can’t perform that action at this time.