Skip to content

Instantly share code, notes, and snippets.

@cfilipov
Created August 25, 2016 03:22
Show Gist options
  • Save cfilipov/bf28d4071efc1f6abac43736a68cb099 to your computer and use it in GitHub Desktop.
Save cfilipov/bf28d4071efc1f6abac43736a68cb099 to your computer and use it in GitHub Desktop.
Undefined Func in Swift
///
/// From: https://realm.io/news/swift-summit-johannes-weiss-the-type-system-is-your-friend/
///
/// Slightly improved:
/// * Report function, file and line of actual call site
/// * Warn usage of this function (somewhat hacky though)
/// * Discardable result
@available(*, deprecated, message: "Use of undefined()")
@discardableResult public func undefined<T>(
_ message: StaticString = ""
, function: StaticString = #function
, file: StaticString = #file
, line: UInt = #line)
-> T {
fatalError(
"undefined(\(message)) in \(function)",
file: file,
line : line)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment