This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
enum CustomColors : String { | |
case | |
listBackground, | |
iPhone13ShowcaseBackground, | |
iPhone13BoxContentBackground, | |
iPadMiniBoxContentBackground |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Example : View { | |
@State private var first: String = "" | |
@State private var second: String = "" | |
var body: some View { | |
Form { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct InfoPListEnvironmentKey : EnvironmentKey { | |
private static var value: InfoPList = .load() | |
static var defaultValue: InfoPList { value } | |
} | |
extension EnvironmentValues { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct StandardPreviews<Content: View> : View { | |
var light: Bool = true | |
var dark: Bool = true | |
var large: Bool = true | |
var small: Bool = true | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
protocol CacheService { | |
func load<T: Cachable>(_ identifier: String) throws -> T? | |
func save<T: Cachable>(_ identifier: String, _ cachable: T) throws | |
func clear<T: Cachable>(_ type: T.Type) throws |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Container : DependencyRegistry, DependencyResolver { | |
private var registrations: [String : () -> Any] = [:] | |
func register<T>(_ t: T.Type, _ f: @escaping @autoclosure () -> T) { | |
registrations[key(for: t)] = f | |
} | |
func resolve<T>() -> T { | |
registrations[key(for: T.self)]!() as! T |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
extension URLRequest { | |
typealias BuilderFunction = ((MultipartFormDataInclusion) -> Void) -> Void | |
struct MultipartFormDataInclusion { | |
var data: Data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Found a weird AF SwiftUI bug today. | |
It's hard to articulate succinctly. I have a demo project that replicates it. | |
Basically if you: | |
- Have a modally presented (via sheet) view which contains a NavigationView and a NavigationLink which leads to a destination view which has an EnvironmentObject dependency AS WELL AS a dependency on the .presentationMode environment value, and... | |
- The user partially dismisses the modally presented view (with the swipe down gesture) without committing to the dismissal, and | |
- Your code inside the modally presented view hierarchy accesses the EnvironmentObject dependency... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct StringTemplate<T> { | |
var template: String | |
init(_ template: String) { | |
self.template = template | |
} | |
func fill(_ t: T) -> String { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio | |
const contrastLightAndDark = (lighter, darker) => (lighter + 0.05) / (darker + 0.05) | |
const relativeLuminance = (r, g, b) => 0.2126 * C(r) + 0.7152 * C(g) + 0.0722 * C(b) | |
const C = c => { | |
const colourScalar = c / 255 | |
return colourScalar <= 0.03928 | |
? colourScalar / 12.92 |
NewerOlder