- iOS Programming Cookbook
- Hossam Ghareeb
- 142字
- 2021-07-09 18:29:42
Optional requirements
You see that when you list your properties and methods in a protocol, the type that conforms to that protocol should adopt to all properties and methods. Skipping one of them will lead to a compiler error. Some protocols may contain methods or properties that are not necessary to implement, especially with delegates. Some delegate methods are meant to notify you something that you don't care about. In that case, you can mark these methods as optional. The keyword optional can be added before properties and methods to mark them as optional. Another thing, the protocol that has optional stuff should be marked with @Objc. Take a look at the following example:
@objc protocol DownloadManagerDelegate { func didDownloadFile(fileURL: String, fileData: NSData) optional func didFailToDownloadFile(fileURL: String, error: NSError) }
It's the new version of DownloadManagerDelegate, which marks didFailToDownloadFile method as optional.
- Implementing Cisco UCS Solutions
- Persistence in PHP with the Doctrine ORM
- Extending Puppet
- 構建可擴展分布式系統:方法與實踐
- Instant Optimizing Embedded Systems using Busybox
- 嵌入式Linux應用開發菜鳥進階
- RESS Essentials
- 網絡操作系統管理與應用(第三版)
- STM32庫開發實戰指南:基于STM32F4
- Dreamweaver CS5.5 Mobile and Web Development with HTML5,CSS3,and jQuery
- Ceph分布式存儲實戰
- OpenStack系統架構設計實戰
- 一學就會:Windows Vista應用完全自學手冊
- Linux設備驅動開發
- Python UNIX和Linux系統管理指南