Swift exit().

pull/1/head
Matthew Chen 6 years ago
parent 90e7d9fbb6
commit 3c22d0b0c8

@ -153,17 +153,22 @@ NS_ASSUME_NONNULL_BEGIN
OWSCFailWithoutLogging(_messageFormat, ##__VA_ARGS__); \
} while (NO)
void SwiftExit(NSString *message, const char *file, const char *function, int line);
#define OWSFail(_messageFormat, ...) \
do { \
OWSFailDebug(_messageFormat, ##__VA_ARGS__); \
exit(0); \
\
NSString *_message = [NSString stringWithFormat:_messageFormat, ##__VA_ARGS__]; \
SwiftExit(_message, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
} while (0)
#define OWSCFail(_messageFormat, ...) \
do { \
OWSCFailDebug(_messageFormat, ##__VA_ARGS__); \
exit(0); \
\
NSString *_message = [NSString stringWithFormat:_messageFormat, ##__VA_ARGS__]; \
SwiftExit(_message, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
} while (NO)
// Avoids Clang analyzer warning:

@ -3,7 +3,15 @@
//
#import "OWSAsserts.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN
void SwiftExit(NSString *message, const char *file, const char *function, int line)
{
NSString *_file = [NSString stringWithFormat:@"%s", file];
NSString *_function = [NSString stringWithFormat:@"%s", function];
[OWSSwiftUtils owsFail:message file:_file function:_function line:line];
}
NS_ASSUME_NONNULL_END

@ -43,7 +43,7 @@ public func owsFail(_ logMessage: String,
file: String = #file,
function: String = #function,
line: Int = #line) -> Never {
owsFailDebug(logMessage, file: file, function: function, line: line)
let formattedMessage = owsFormatLogMessage(logMessage, file: file, function: function, line: line)
fatalError(formattedMessage)
@ -56,4 +56,16 @@ public func notImplemented(file: String = #file,
line: Int = #line) -> Never {
owsFail("Method not implemented.", file: file, function: function, line: line)
}
@objc public class OWSSwiftUtils: NSObject {
// This method can be invoked from Obj-C to exit the app.
@objc public class func owsFail(_ logMessage: String,
file: String = #file,
function: String = #function,
line: Int = #line) -> Never {
owsFailDebug(logMessage, file: file, function: function, line: line)
let formattedMessage = owsFormatLogMessage(logMessage, file: file, function: function, line: line)
fatalError(formattedMessage)
}
}

Loading…
Cancel
Save