Skip to content

Instantly share code, notes, and snippets.

@xcadaverx
xcadaverx / Spinner.swift
Created August 31, 2022 22:44
[Spinner] a simple loading spinner for SwiftUI
struct Spinner: View {
var outerColor = Color.blue
var innerColor = Color.red
@State private var isAnimating = false
var body: some View {
GeometryReader { proxy in
@xcadaverx
xcadaverx / Interpolatable+Common.swift
Created October 7, 2020 18:10
[@interpolated] A property wrapper to interpolate between values #swift #ios #propertyWrapper
// MARK: - Interpolatable+Common
extension Double: Interpolatable {
static func makeWithInterpolationValues(interpolationValues: [Double]) -> Double {
interpolationValues[0]
}
var interpolationValues: [Double] { [self] }
}
@xcadaverx
xcadaverx / Race.swift
Last active October 15, 2020 18:30
[Combine.Publisher.Race] Custom Combine implementation of Race or amb
import Foundation
import Combine
// MARK: - Either (Output)
enum Either<Left, Right> {
case left(Left)
case right(Right)
}

Keybase proof

I hereby claim:

  • I am xcadaverx on github.
  • I am xcadaverx (https://keybase.io/xcadaverx) on keybase.
  • I have a public key ASATRpD2PGI3459h_hRaLfWrTTesKAAlgTZez4aoXGKMwAo

To claim this, I am signing this object:

protocol Foo {}
let fooSubclassOne: Foo = FooSubClass()
fooSubclassOne.bar() // Foo.bar()
let fooSubclassTwo: SomeFoo = FooSubClass()
fooSubclassTwo.bar() // FooSubClass.bar()
let fooSubClassThree: FooSubClass = FooSubClass()
fooSubClassThree.bar() // FooSubClass.bar()
class FooSubClass: SomeFoo {
override func bar() {
print("FooSubClass.bar()")
}
}
let fooSubClass: Foo = FooSubClass()
fooSubClass.bar() // FooSubClass.bar()
let fooSubClassTwo: SomeFoo = FooSubClass()
class SomeFoo: Foo {
func bar() {
print("SomeFoo.bar()")
}
}
let someFoo: Foo = SomeFoo()
someFoo.bar() // SomeFoo.bar()
let anotherFoo: SomeFoo = SomeFoo()
class FooSubClass: SomeFoo {}
extension Foo where Self: FooSubClass {
func bar() {
print("Foo.FooSubclass.bar()")
}
}
let fooSubClassOne: Foo = FooSubClass()
fooSubClassOne.bar() // Foo.SomeFoo.bar() 🤨
extension Foo where Self: SomeFoo {
func bar() {
print("Foo.SomeFoo.bar()")
}
}
let someFoo: SomeFoo = SomeFoo()
someFoo.bar() // Foo.SomeFoo.bar()
let anotherFoo: Foo = SomeFoo()
protocol Foo {
func bar()
}
extension Foo {
func bar() {
print("Foo.bar()")
}
}