Skip to content

Instantly share code, notes, and snippets.

💭
🤔🤔🤔

Isaac Carol Weisberg isaac-weisberg

💭
🤔🤔🤔
Block or report user

Report or block isaac-weisberg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View AppDelegate.swift
controller.viewModel.authError
.bind(onNext: { [unowned controller] error in
let authController = AuthErrorController.instantiate()
authController.viewModel = AuthErrorViewModel(presenter: error)
authController.viewModel.logIn
.bind(onNext: { [unowned controller] _ in
controller.dismiss(animated: true)
})
View MainViewModel.4.swift
authError = forecast
.map { result -> AuthErrorModelRepresentable? in
switch result.lastResult {
case .none, .success:
return nil
case .failure(let reason):
switch reason {
case .downloadError(let reason):
switch reason {
case .download(let reason):
View AuthErrorFromMain.swift
import UIKit
struct AuthErrorFromMain: AuthErrorModelRepresentable {
var authErrorModel: AuthErrorModelType {
return AuthErrorModel(
title: "Authorization issue",
description: "You have tried to get a forecast, but it seems that you aren't logged in",
image: [
"timmyb",
"idupes",
View MainViewController.3.swift
viewModel.majorError
.bind(onNext: { [unowned self] error in
let errorUserFriendly = error.errorTitleSingular
let alert = UIAlertController(
title: errorUserFriendly.title,
message: errorUserFriendly.singularDescription,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { _ in }))
View MainViewModel.3.swift
extension BusinessLogicError: ErrorTitledSingularRepresentable {
var errorTitleSingular: ErrorTitledSingularType {
switch self {
case .temperatureInvalid(let temp):
return ErrorTitledSingular("No wait", "\(temp) doesn't seem quite right")
case .downloadError(let reason):
return reason.errorTitleSingular
}
}
}
View ForecastDownloadService.3.swift
extension ForecastDownloadError: ErrorTitledSingularRepresentable {
var errorTitleSingular: ErrorTitledSingularType {
switch self {
case .parsing:
return ErrorTitledSingular("Dang it", "There was a problem decoding the forecast")
case .download(let reason):
return reason.errorTitleSingular
}
}
}
View DataDownloadService.3.swift
extension DataDownloadServiceError: ErrorTitledSingularRepresentable {
var errorTitleSingular: ErrorTitledSingularType {
switch self {
case .noData:
return ErrorTitledSingular("Yikes!", "The server must be hung over tbh")
case .invalidResponseType:
return ErrorTitledSingular("Darn", "Ooops, guess we've goofed up")
case .networkError(let error):
return ErrorTitledSingular("Error", error.localizedDescription)
case .unexpectedStatusCode(let code):
View MainViewController.swift
class MainViewController: UIViewController {
@IBOutlet var bottomErrorContainer: UIView!
@IBOutlet var bottomErrorLabel: UILabel!
func viewDidLoad() {
// ...
viewModel.minorError
View MainViewModel.2.swift
struct MainViewModel {
let minorError: Observable<String?>
init(deps: Deps, temperatureRange: ClosedRange<Double>) {
let newForecastRecieved: Observable<Result<ForecastDTO, BusinessLogicError>> = // something
minorError = newForecastRecieved
.map { result -> String? in
switch result {
View MainViewModel.swift
private enum BusinessLogicError: Error {
case downloadError(ForecastDownloadError)
case temperatureInvalid(Double)
}
struct MainViewModel {
/* implementation omitted, but includes
the logic of validating the temperature */
}
You can’t perform that action at this time.