Last active
November 13, 2015 11:29
-
-
Save ilyapuchka/28aee3ac5af4133ec93d to your computer and use it in GitHub Desktop.
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 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