Skip to content

Instantly share code, notes, and snippets.

@jesusdomin
Created October 3, 2014 06:36
Show Gist options
  • Save jesusdomin/a5588cfbcaa9c815459d to your computer and use it in GitHub Desktop.
Save jesusdomin/a5588cfbcaa9c815459d to your computer and use it in GitHub Desktop.
Asserts in swift
// More Info: https://developer.apple.com/swift/blog/?id=15
func assert(condition: @autoclosure () -> Bool, _ message: String = "", file: String = __FILE__, line: Int = __LINE__) {
#if DEBUG
if !condition() {
println("assertion failed at \(file):\(line): \(message)")
abort()
}
#endif
}
func logAndAssert(condition: @autoclosure () -> Bool, _ message: StaticString = "", file: StaticString = __FILE__, line: UWord = __LINE__) {
logMessage(message)
assert(condition, message, file: file, line: line)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment