Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
let now = Date()
var future = now
print("equal: \(now == future)")
// equal: true
future += 1 * 60 * 60
print("not equal: \(now == future)")
// not equal: false
future -= 2 * 60 * 60
print("now > future?: \(now > future)")
var date = Date(timeIntervalSince1970: 50 * 365 * 24 * 60 * 60)
print("date: \(date)")
// console: date: 2019-12-20 00:00:00 +0000
enum EmailValidationError: Error {
// TODO: - Cases
case empty
// TODO: - Cases can be declared on a single line
case noDomain(String)
case invalid(String)
}
extension EmailValidationError: LocalizedError {
enum Weekday: Int {
case sun
case mon
case tue
case wed
case thur
case fri
case sat
var value: String {
enum EmailValidationError {
// TODO: - Cases
case empty
// TODO: - Cases can be declared on a single line
case noDomain(String)
case invalid(String)
}
// TODO: - Create a new error
var error = EmailValidationError.empty
enum EmailValidationError: CaseIterable {
// TODO: - Cases
case empty
// TODO: - Cases can be declared on a single line
case noDomain, invalid
}
print("All cases: \(EmailValidationError.allCases)")
// TODO: - Just print all enum cases
switch error {
case .empty:
print("Please provide email")
case .noDomain:
print("Add domain")
case .invalid:
print("Entered email looks like invaid")
}
if signupError == .invalid {
// TODO: - Create a new error
var error = EmailValidationError.empty
// TODO: - OR type-inferred
var signupError: EmailValidationError = .invalid
error = .noDomain
enum EmailValidationError {
// TODO: - Cases
case empty
// TODO: - Cases can be declared on a single line
case noDomain, invalid
}
@IBInspectable
var activeSegmentColor: UIColor = .segmentActiveBackground
@IBInspectable
var textColor: UIColor = .segmentText
@IBInspectable
var activeTextColor: UIColor = .segmentActiveText