Skip to content

Instantly share code, notes, and snippets.

View afarnham's full-sized avatar

Aaron Farnham afarnham

View GitHub Profile
@afarnham
afarnham / gist:1e80647c23eb36cf99f2
Created June 26, 2015 21:24
Dynamic instantiation of Swift classes conforming to a specific protocol
import UIKit
protocol FooProtocol {
init()
func description() -> String
}
class Bar : FooProtocol {
required init() {
### Keybase proof
I hereby claim:
* I am afarnham on github.
* I am afarnham (https://keybase.io/afarnham) on keybase.
* I have a public key whose fingerprint is 96B3 8D77 96D4 F6D3 3081 881B 3C38 2A68 DF5B 32FE
To claim this, I am signing this object:
TextField("Target Weight", text: $viewModel.inputWeight)
                    .keyboardType(.decimalPad)
                    .onChange(of: viewModel.inputWeight, perform: { value in
                        viewModel.inputWeight = value.filter { "01234567890.".contains($0) }
                    })