Skip to content

Instantly share code, notes, and snippets.

@ilyapuchka
Last active November 13, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyapuchka/28aee3ac5af4133ec93d to your computer and use it in GitHub Desktop.
Save ilyapuchka/28aee3ac5af4133ec93d to your computer and use it in GitHub Desktop.
class Stub<ArgumentsType> {
let argumentsMatcher: ArgumentsType -> Bool
init(matcher: ArgumentsType -> Bool) {
self.argumentsMatcher = matcher
}
}
var stubs = [Any]()
let stub1 = Stub<String>(matcher: { (arg: String) -> Bool in
return true
})
let stub2 = Stub<String>(matcher: { (arg: String) -> Bool in
return true
})
stubs = [stub1, stub2]
//this crashes on second iteration
if let stubs = stubs as? [Stub<String>] {
for stub in stubs {
stub.argumentsMatcher("some string")
}
}
//this works
for stub in stubs {
if let typedStub = stub as? Stub<String> {
typedStub.argumentsMatcher("some string")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment