- 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.
推薦閱讀
- JavaScript前端開發(fā)模塊化教程
- 零基礎(chǔ)學(xué)C++程序設(shè)計(jì)
- JavaScript:Functional Programming for JavaScript Developers
- Learning Bayesian Models with R
- Django Design Patterns and Best Practices
- Python Network Programming Cookbook(Second Edition)
- 精通網(wǎng)絡(luò)視頻核心開發(fā)技術(shù)
- 精通Linux(第2版)
- Python忍者秘籍
- Java Web開發(fā)詳解
- Terraform:多云、混合云環(huán)境下實(shí)現(xiàn)基礎(chǔ)設(shè)施即代碼(第2版)
- ASP.NET程序開發(fā)范例寶典
- Spring Boot+Vue全棧開發(fā)實(shí)戰(zhàn)
- 深入理解BootLoader
- Hadoop Blueprints