Created
January 9, 2018 08:09
-
-
Save vialyx/dfddb3e940bf96985af9fcb10a4d4598 to your computer and use it in GitHub Desktop.
This file contains 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
import UIKit | |
var str = "Hello, playground" | |
class BaseViewController: UIViewController { | |
var handledErrorCodes: [Int: String] = [200: "localized.title", 210: "localized.title.error"] | |
func showError(error: NSError) { | |
let code = error.code | |
guard handledErrorCodes.keys.contains(code), let text = handledErrorCodes[code] as? String else { | |
print("\(self) can't handle this error code \(code)") | |
return | |
} | |
switch code { | |
case 200: | |
print("\(self) handle 200 code \(text)") | |
case 210: | |
print("\(self) handle 210 code \(text)") | |
default: | |
print("\(self) handle unknown code \(text)") | |
} | |
} | |
} | |
class RootViewController: BaseViewController {} | |
class ProfileViewController: BaseViewController {} | |
let error = NSError(domain: "cactussoft", code: 210, userInfo: nil) | |
let base = BaseViewController() | |
base.showError(error: error) | |
let root = RootViewController() | |
root.handledErrorCodes = [211: "localized.title", 220: "localized.title.error"] | |
root.showError(error: error) | |
let profile = ProfileViewController() | |
profile.handledErrorCodes = [310: "localized.title", 120: "localized.title.error"] | |
profile.showError(error: error) | |
let error211 = NSError(domain: "cactussoft", code: 211, userInfo: nil) | |
profile.showError(error: error211) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment