Skip to content

Instantly share code, notes, and snippets.

View soffes's full-sized avatar

Sam Soffes soffes

View GitHub Profile
@soffes
soffes / Rakefile
Last active January 16, 2023 16:37
Programmatically build and sign a Developer ID macOS app
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 July 1, 2023 10:14
Fast, concrete text storage intended to be subclassed.
import UIKit
/// Fast, concrete text storage intended to be subclassed.
class BaseTextStorage: NSTextStorage {
// MARK: - Properties
private let storage = NSMutableAttributedString()
// MARK: - NSTextStorage
@soffes
soffes / BaseTextStorage.h
Last active July 1, 2023 10:14
BaseTextStorage (Objective-C)
@import Darwin.TargetConditionals;
#if TARGET_OS_IPHONE
@import UIKit;
#else
@import AppKit;
#endif
/// Concrete text storage intended to be subclassed.
@interface BaseTextStorage : NSTextStorage
@soffes
soffes / WebCredential.swift
Last active November 25, 2022 08:24
Easily access Shared Web Credentials
import Foundation
import Security
struct SharedWebCredentials {
// MARK: - Types
struct Credential {
let domain: String
let account: String
@soffes
soffes / UISplitViewController+Soffes.swift
Created June 8, 2016 22:23
Easily access master and detail view controllers on UISplitViewController
import UIKit
extension UISplitViewController {
convenience init(masterViewController: UIViewController, detailViewController: UIViewController) {
self.init()
viewControllers = [masterViewController, detailViewController]
}
var masterViewController: UIViewController? {
return viewControllers.first
@soffes
soffes / UIColor+Desaturated.swift
Created June 6, 2016 23:48
Desaturate a UIColor
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)
$ 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 June 3, 2016 22:28
Plain table view section header replacement
import UIKit
class SectionHeaderView: UIView {
// MARK: - Properties
let textLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = .boldSystemFontOfSize(17)
@soffes
soffes / NavigationBar.swift
Created June 3, 2016 22:03
Change navigation bar border color
import UIKit
class NavigationBar: UINavigationBar {
// MARK: - Properties
var borderColor: UIColor? {
set {
borderView.backgroundColor = newValue
}
@soffes
soffes / LineView.swift
Last active June 8, 2016 21:48
Thin lines
import UIKit
class LineView: UIView {
override func sizeThatFits(size: CGSize) -> CGSize {
return CGSize(width: size.width, height: intrinsicContentSize().height)
}
override func intrinsicContentSize() -> CGSize {
return CGSize(width: UIViewNoIntrinsicMetric, height: 1 / max(1, traitCollection.displayScale))
}