Skip to content

Instantly share code, notes, and snippets.

@marcisme
Created July 24, 2017 19:56
Show Gist options
  • Save marcisme/ae06e1c45e9eacba9bf8194a264ccd69 to your computer and use it in GitHub Desktop.
Save marcisme/ae06e1c45e9eacba9bf8194a264ccd69 to your computer and use it in GitHub Desktop.
//
// MSSAssertions.swift
// FastOne
//
// Created by Marc Schwieterman on 3/8/15.
// Copyright (c) 2015 Marc Schwieterman Software, LLC. All rights reserved.
//
import Foundation
private let MSSAssertionFailureExceptionName = "MSSAssertionFailure"
private class MSSAssertionFailureException: NSException {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
required init(reason: String) {
super.init(name: NSExceptionName(rawValue: MSSAssertionFailureExceptionName), reason: reason, userInfo: nil)
}
}
func MSSAssert(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String, file: String = #file, line: Int = #line) {
if !condition() {
MSSAssertionFailure(message, file: file, line: line)
}
}
func MSSAssertionFailure(_ message: @autoclosure () -> String, file: String = #file, line: Int = #line) -> Never {
let fileName = file.characters.split(separator: "/").last
let reason = "\(fileName):\(line) \(message())"
// We're using exceptions as our crash mechanism because their message will be included in
// Hockey crash reports. In addition to being disabled in release builds by default, the
// message text for the default Swift assertions is not included in crash reports.
MSSAssertionFailureException(reason: reason).raise()
abort() // compiler placation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment