- iOS Programming Cookbook
- Hossam Ghareeb
- 99字
- 2021-07-09 18:29:41
Mutating methods
Swift allows you mark protocol methods as mutating when it's necessary for these methods to mutate (modify) the instance value itself. This is applicable only in structures and enumerations; we call them value types. Consider this example of using mutating:
protocol Togglable{ mutating func toggle() } enum Switch: Togglable{ case ON case OFF mutating func toggle() { switch self { case .ON: self = OFF default: self = ON } } }
The Switch enum implements the method toggle, as it's defined in the protocol Togglable. Inside toggle(), we could update self-value as function marked as mutating.
推薦閱讀
- Linux設(shè)備驅(qū)動(dòng)開發(fā)詳解:基于最新的Linux4.0內(nèi)核
- Windows Server 2019 Cookbook
- Haskell Financial Data Modeling and Predictive Analytics
- 構(gòu)建可擴(kuò)展分布式系統(tǒng):方法與實(shí)踐
- 深入理解eBPF與可觀測(cè)性
- 嵌入式Linux應(yīng)用開發(fā)菜鳥進(jìn)階
- Linux運(yùn)維最佳實(shí)踐
- OpenSolaris設(shè)備驅(qū)動(dòng)原理與開發(fā)
- AWS SysOps Cookbook
- Hands-On GPU Programming with Python and CUDA
- Linux 從入門到項(xiàng)目實(shí)踐(超值版)
- Windows Server 2008組網(wǎng)技術(shù)與實(shí)訓(xùn)(第3版)
- Drupal 7 Cookbook
- Multi-Cloud for Architects
- BuddyPress Theme Development