Skip to content

Instantly share code, notes, and snippets.

@shawnthroop
shawnthroop / Raw.swift
Last active May 14, 2018 09:42
Possible typesafe keys and values for representing pnut.io's Raw data
import Foundation
let data = """
{
"version": "1.0",
"type": "photo",
"width": 240,
"height": 160,
"title": "ZB8T0193",
"url": "http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg",
@shawnthroop
shawnthroop / List.swift
Created March 18, 2018 17:25
List and OptimizedList, a sectioned Collection.
struct List<Element>: Sequence, Collection where Element: Hashable {
private var contents: [[Element]]
init(_ sections: [[Element]] = [[]]) {
contents = sections
}
// MARK: - Sequence
@shawnthroop
shawnthroop / UIColor+Additions.swift
Last active May 29, 2017 12:22
Additions to UIColor that allow for easier manipulation of RGBA and HSBA values, in Swift
import UIKit
extension UIColor {
struct HSBA {
var hue: CGFloat
var saturation: CGFloat
var brightness: CGFloat
var alpha: CGFloat
@shawnthroop
shawnthroop / NSRange+SurrogatePairAdjustable.swift
Last active April 18, 2018 15:26
Adjusting ranges retrieved from an API (App.net, pnut.io, etc.) for use with NSAttributedString
// Swift 4.0.3
import Foundation
extension NSRange: SurrogatePairAdjustable {
func adjusted(for pairs: [String.SurrogatePair]) -> NSRange {
if pairs.isEmpty {
return self
}
@shawnthroop
shawnthroop / PRSModalWebViewController.h
Created January 5, 2015 01:35
A self contained UINavigationViewController and UIViewController for presenting a WKWebView on iOS 8
#import <WebKit/WebKit.h>
@protocol PRSProgressDelegate <NSObject>
- (void)setNavigationTitle:(NSString *)title;
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated;
- (void)setVisible:(BOOL)visible animated:(BOOL)animated;
@end