- iOS Programming Cookbook
- Hossam Ghareeb
- 127字
- 2021-07-09 18:29:45
Getting ready
Before starting to learn how to handle errors in Swift, you first have to be familiar with how to represent in errors that are going to happen in your program. Swift provides you with a protocol called ErrorType that your errors types should adopt. Then, to represent errors, here comes the role of enumerations to help you. You create a new enum, which lists all error cases, and this enum should conform to the ErrorType protocol. The syntax of using enum with ErrorType will be something like this:
enum DBConnectionError: ErrorType{ case ConnectionClosed case DBNotExist case DBNotWritable }
As we see it's pretty straightforward. You create enum representing the error that conforms to ErrorType protocol, and then list all errors as cases in the enum.
推薦閱讀
- 從零開始寫Linux內(nèi)核:一書學(xué)透核心原理與實現(xiàn)
- Persistence in PHP with the Doctrine ORM
- 操作系統(tǒng)基礎(chǔ)與實踐:基于openEuler平臺
- Learn Helm
- 嵌入式Linux系統(tǒng)開發(fā):基于Yocto Project
- Ubuntu Linux操作系統(tǒng)
- Implementing Azure DevOps Solutions
- Docker+Kubernetes應(yīng)用開發(fā)與快速上云
- AWS SysOps Cookbook
- INSTANT Galleria Howto
- Vim 8文本處理實戰(zhàn)
- 電腦辦公(Windows 10 + Office 2016)入門與提高(超值版)
- Windows網(wǎng)絡(luò)編程(第2版)
- openEuler操作系統(tǒng)核心技術(shù)與行業(yè)應(yīng)用實踐
- OpenSolaris紅寶書