- Reactive Programming with Swift 4
- Navdeep Singh
- 151字
- 2021-06-24 18:57:59
Bid bye to string.characters
As part of the changes, this is one of the most welcomed changes. This change eliminates the necessity for a characters array on String, which means now you can reverse them, loop over them character-by-character, map() and flatMap() them, and more than anything, you can now iterate directly over a String object:
let vowels = "AEIOU"
for char in vowels {
print(char)
}
This prints the following:
A , E , I , O, U
Here, you not only get logical iteration through String, but also specific understanding for collection and sequence:
vowels.count , result is 5, no need of vowels.characters.count
vowels.isEmpty , result is false
vowels.dropFirst() , result is "EIOU"
String(vowels.reversed()) , result is "UOIEA"
There is a small improvement to the way characters behave—now you can obtain the UnicodeScalarView straight from the character, whereas earlier, instantiation of a new String was needed.
推薦閱讀
- TypeScript Essentials
- 測試驅動開發:入門、實戰與進階
- Access 數據庫應用教程
- 深入淺出Java虛擬機:JVM原理與實戰
- Magento 2 Theme Design(Second Edition)
- 大學計算機基礎(第2版)(微課版)
- JavaScript 程序設計案例教程
- Web Development with MongoDB and Node(Third Edition)
- Windows Embedded CE 6.0程序設計實戰
- Arduino計算機視覺編程
- OpenStack Networking Essentials
- 人工智能算法(卷1):基礎算法
- Backbone.js Testing
- Python數據科學實踐指南
- 基于JavaScript的WebGIS開發