Skip to content

Instantly share code, notes, and snippets.

View hvsw's full-sized avatar

Henrique Valcanaia hvsw

View GitHub Profile
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
enum DivisionErrorEnum: ErrorType {
case DividendIsZero(message: String)
case DivisorIsZero(message: String)
}
@hvsw
hvsw / MyError.swift
Last active September 17, 2016 17:15
enum MyError: ErrorType {
case AnError,
case AnotherError(message: String)
}
protocol ErrorType {
var _domain: Swift.String { get }
var _code: Swift.Int { get }
}
extension ErrorType {
public var _domain: String {
return String(reflecting: self.dynamicType)
}
}
public protocol ErrorType {}
extension ErrorType {}
@hvsw
hvsw / iOS7-notifications.h
Created January 3, 2016 06:09 — forked from hpique/iOS7-notifications.h
List of all public notifications available in iOS 7.0 (or at least those whose constants are properly named).
// 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;