Skip to content

Instantly share code, notes, and snippets.

View ComposableSearchable.swift
import SwiftUI
import ComposableArchitecture
struct SearchableState: Equatable {
var searchText = ""
var names = ["Oliver", "Emily", "Jessica", "Dan", "Eva"]
var searchResults: [String] {
if searchText.isEmpty {
return names
View ViewModelSearchable.swift
import Foundation
import SwiftUI
class SearchableViewModel: ObservableObject {
let names = ["Oliver", "Emily", "Jessica", "Daniel", "Eva"]
@Published var searchText: String = ""
var searchResults: [String] {
if searchText.isEmpty {
View VanillaSearchable.swift
import Foundation
import SwiftUI
struct VanillaSearchableView: View {
let names = ["Oliver", "Emily", "Jessica", "Daniel", "Eva"]
@State var searchText: String = ""
var body: some View {
NavigationView {
List {
View gist:9ce9008ddf22974f963a3cfbd565b629
import UIKit
class BuyButton: UIView {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//MARK: - View
backgroundColor = UIColor(red: 180/255, green: 35/255, blue: 115/255, alpha: 1)
layer.cornerRadius = 3
oliverfoggin / GKRuleSystemValidator.swift
Last active Dec 7, 2016
GameplayKit GKRuleSystem Validator
View GKRuleSystemValidator.swift
import Foundation
import GameplayKit
enum ValidationResult<T: Error> {
case valid
case invalid(error: T)
class Fact<T: Error>: NSObject {
let error: T
View Router.swift
enum Router: URLRequestConvertible {
static let baseURLString = ""
static var OAuthToken: String? {
didSet {
// save token to keychain
case AuthCheck
View gist:e22aa20675e68f17a163
// Challenge set here...
import UIKit
// convenience for printing
func moveRing(ring : Int, currentPole: Int, targetPole: Int) {
println("Move ring \(ring) from pole \(currentPole) to pole \(targetPole)")
oliverfoggin / gist:0569e25ec93a0cc38187
Last active Aug 29, 2015
Programmin Challenge: the position of the element (Messing around in Swift)
View gist:0569e25ec93a0cc38187
import UIKit
// binary search function to find position
func findPositionInArray<T: Comparable>(array: [T], value: T) -> Int {
var lowerIndex = 0
var upperIndex = array.count - 1
while lowerIndex < upperIndex {
let currentIndex = lowerIndex + Int(Double(upperIndex - lowerIndex) * 0.5)
let currentValue = array[currentIndex]
oliverfoggin / gist:10024117
Last active Aug 29, 2015
Failing UISearchDisplayController
View gist:10024117
#import "UserSearchViewController.h"
@interface UserSearchViewController () <UISearchBarDelegate, UISearchDisplayDelegate>
@implementation UserSearchViewController
- (void)viewDidLoad
oliverfoggin / gist:9743873
Last active Aug 29, 2015
Search for a book by its cover
View gist:9743873
== Search for a book by its cover
Playing on the saying "Don't judge a book by its cover" I created this so that if you see a book online or in a shop but you forget what it's called you can find it by recalling details about the cover.
[source, cypher]