Skip to content

Instantly share code, notes, and snippets.

@oliverfoggin
oliverfoggin / ContentView.swift
Last active November 7, 2022 19:18
SwiftUI bug with TabBars and switching them out for other views
import SwiftUI
struct ContentView: View {
@State var loggedIn: Bool = false
var body: some View {
switch loggedIn {
case false:
Button("Login") {
loggedIn = true
@oliverfoggin
oliverfoggin / gist:7e2c5ab5e6973aa52187b66b776f1db6
Created January 15, 2022 16:46
Collection view reload data only reloading items once each...
import UIKit
class MyCollectionViewCell: UICollectionViewCell {
let label: UILabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
contentView.addSubview(label)
@oliverfoggin
oliverfoggin / identifier.swift
Last active December 7, 2021 22:10
Type Safe Identifiers with automatic conformance to Identifiable
/// This was inspired by this... https://www.swiftbysundell.com/articles/type-safe-identifiers-in-swift/
/// I wanted to try and find a way to have a type safe identifier that also allowed conformance to Identifiable
import Foundation
struct Identifier<Subject: Identified>: Hashable {
let value: Subject.IdentifierType
init(_ value: Subject.IdentifierType) {
self.value = value
@oliverfoggin
oliverfoggin / identifier.swift
Created December 7, 2021 22:03
Type Safe Identifiers with automatic conformance to Identifiable
/// This was inspired by this... https://www.swiftbysundell.com/articles/type-safe-identifiers-in-swift/
/// I wanted to try and find a way to have a type safe identifier that also allowed conformance to Identifiable
import Foundation
struct Identifier<Subject: Identified>: Hashable {
let value: Subject.IdentifierType
init(_ value: Subject.IdentifierType) {
self.value = value
@oliverfoggin
oliverfoggin / gist:697e9340a5705800adf6ec5ae4cac29d
Created October 24, 2021 18:58
Trying to recreate the behaviour of Optional...
enum Foo<Wrapped> {
case no
case yes(Wrapped)
}
extension Foo: ExpressibleByNilLiteral {
init(nilLiteral: ()) {
self = .no
}
}
import SwiftUI
import ComposableArchitecture
struct SearchableState: Equatable {
var searchText = ""
var names = ["Oliver", "Emily", "Jessica", "Dan", "Eva"]
var searchResults: [String] {
if searchText.isEmpty {
return names
import Foundation
import SwiftUI
class SearchableViewModel: ObservableObject {
let names = ["Oliver", "Emily", "Jessica", "Daniel", "Eva"]
@Published var searchText: String = ""
var searchResults: [String] {
if searchText.isEmpty {
import Foundation
import SwiftUI
struct VanillaSearchableView: View {
let names = ["Oliver", "Emily", "Jessica", "Daniel", "Eva"]
@State var searchText: String = ""
var body: some View {
NavigationView {
List {
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
oliverfoggin / GKRuleSystemValidator.swift
Last active December 7, 2016 11:51
GameplayKit GKRuleSystem Validator
import Foundation
import GameplayKit
enum ValidationResult<T: Error> {
case valid
case invalid(error: T)
}
class Fact<T: Error>: NSObject {
let error: T