Skip to content

Instantly share code, notes, and snippets.

@Ben-G
Last active January 24, 2016 04:21
Show Gist options
  • Save Ben-G/e201cfb68652e1ab141f to your computer and use it in GitHub Desktop.
Save Ben-G/e201cfb68652e1ab141f to your computer and use it in GitHub Desktop.
Does not crash compiler
public protocol X {
func _ok(a: Any)
}
public protocol StoreSubscriber: X {
typealias StoreSubscriberStateType
typealias AppStateType
func newState(state: StoreSubscriberStateType)
func substateSelector(state: AppStateType) -> StoreSubscriberStateType
}
extension StoreSubscriber {
public func _ok(a: Any) {
if let a = a as? StoreSubscriberStateType {
newState(a)
}
}
}
struct A {
var substate: Int
}
class Thing: StoreSubscriber {
func newState(state: Int) {
print(state)
}
func substateSelector(state: A) -> Int {
return state.substate
}
}
let substate = Thing().substateSelector(A(substate: 5))
Thing().newState(substate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment