Last active
April 27, 2016 04:49
-
-
Save jmnavarro/25c6c003d8f2ecee4be8 to your computer and use it in GitHub Desktop.
Since it seems XCTAssertNotNil is not working with Swift's optional, this is an alternative method. In order to stop execution when test fails, check XCTestCase's continueAfterFailure property
This file contains 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
func XCTAssertOptional(expression: @autoclosure () -> AnyObject?, _ message: String? = nil) { | |
let evaluatedExpression:AnyObject? = expression() | |
if evaluatedExpression == nil { | |
if let messageValue = message { | |
XCTFail(messageValue) | |
} | |
else { | |
XCTFail("Optional asertion failed: \(evaluatedExpression)") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you update to support latest Swift, on Xcode 7.3 its suggesting the following change to method signature
ie it has removed the @autoclosure
with warning - "Closure parameter prior to parameters with default arguments will not be treated as a trailing closure"