This file contains hidden or 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
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestCaseRun.h | |
SENTEST_EXPORT NSString * const SenTestCaseDidStartNotification; | |
SENTEST_EXPORT NSString * const SenTestCaseDidStopNotification; | |
SENTEST_EXPORT NSString * const SenTestCaseDidFailNotification; | |
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestDistributedNotifier.h | |
SENTEST_EXPORT NSString * const SenTestNotificationIdentifierKey; | |
// Developer/Library/Frameworks/SenTestingKit.framework/Headers/SenTestSuiteRun.h | |
SENTEST_EXPORT NSString * const SenTestSuiteDidStartNotification; |
This file contains hidden or 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
public protocol ErrorType {} | |
extension ErrorType {} |
This file contains hidden or 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
protocol ErrorType { | |
var _domain: Swift.String { get } | |
var _code: Swift.Int { get } | |
} | |
extension ErrorType { | |
public var _domain: String { | |
return String(reflecting: self.dynamicType) | |
} | |
} |
This file contains hidden or 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
enum MyError: ErrorType { | |
case AnError, | |
case AnotherError(message: String) | |
} |
This file contains hidden or 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
enum DivisionErrorEnum: ErrorType { | |
case DividendIsZero(message: String) | |
case DivisorIsZero(message: String) | |
} |
This file contains hidden or 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 divide(x: Float, _ y: Float) throws -> Float { | |
guard x != 0 else { | |
throw DivisionErrorEnum.DividendIsZero(message: "You’re trying to divide 0") | |
} | |
guard y != 0 else { | |
throw DivisionErrorEnum.DivisorIsZero(message: "You’re trying to divide \(x) by 0") | |
} | |
return x/y |
This file contains hidden or 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 calculate() { | |
do { | |
let x:Float = 2.0 | |
let y:Float = 2.0 | |
let result = try divide(x, y) | |
resultLabel.text = String(result) | |
} catch DivisionErrorEnum.DividendIsZero(let msg) { | |
print(msg) | |
} catch DivisionErrorEnum.DivisorIsZero(let msg) { | |
print(msg) |
This file contains hidden or 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
enum DivisionErrorEnum: ErrorType { | |
case DividendIsZero(code: Int) | |
case DivisorIsZero(code: Int) | |
} |
This file contains hidden or 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 calculate() { | |
do { | |
let x = 2 | |
let y = 2 | |
let result = try divide(x, y) | |
resultLabel.text = String(result) | |
} catch DivisionErrorEnum.DividendIsZero(let code) { | |
print("Your message when the DIVIDEND is zero. \nDetails: Execution failed with code \(code).") | |
} catch DivisionErrorEnum.DivisorIsZero(let code) { | |
print("Your custom message when the DIVISOR is zero. \nDetails: Execution failed with code \(code).") |
This file contains hidden or 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
// Using optional try | |
let x = try? divide(0, 2) // (Yes you can use an if let/guard/whatever to unwrap it safely) | |
// Using do-catch | |
let y: Float? | |
do { | |
y = try divide(0, 2) | |
} catch { // exhaustive just for testing | |
y = nil | |
} |
OlderNewer