- iOS Programming Cookbook
- Hossam Ghareeb
- 121字
- 2021-07-09 18:29:43
How to do it...
- Create a new playground file in Xcode called Extensions.
- Create extension for double value by adding computing properties, as follows:
extension Double{ var absoluteValue: Double{ return abs(self) } var intValue: Int{ return Int(self) } } extension String{ var length: Int{ return self.characters.count } } let doubleValue: Double = -19.5 doubleValue.absoluteValue // 19.5 doubleValue.intValue // 19 extension Int{ func isEven() ->Bool{ return self % 2 == 0 } func isOdd() ->Bool{ return !isEven() } func digits() -> [Int]{ var digits = [Int]() var num = self repeat { let digit = num % 10 digits.append(digit) num /= 10 } while num != 0 return digits } } let num = 12345 num.digits() // [5, 4, 3, 2, 1]
推薦閱讀
- Windows Server 2012 Hyper-V:Deploying the Hyper-V Enterprise Server Virtualization Platform
- Mastering Distributed Tracing
- Kali Linux滲透測試全流程詳解
- 嵌入式Linux系統開發:基于Yocto Project
- Linux集群和自動化運維
- Windows Phone應用程序開發
- Linux系統安全基礎:二進制代碼安全性分析基礎與實踐
- 嵌入式實時操作系統μC/OS原理與實踐
- 跟老男孩學Linux運維:Shell編程實戰
- Windows 7實戰從入門到精通
- 從零開始學安裝與重裝系統
- Mastering Windows 8 C++ App Development
- Responsive Web Design with AngularJS
- Gradle Effective Implementations Guide(Second Edition)
- Instant Responsive Web Design