官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 新干县| 临高县| 塔城市| 芮城县| 文安县| 陇西县| 通州区| 华坪县| 泸水县| 揭东县| 沾化县| 来凤县| 柯坪县| 西乌珠穆沁旗| 星座| 仙游县| 宜都市| 松桃| 玉田县| 松溪县| 芦溪县| 来凤县| 鄂州市| 三门县| 那坡县| 鄂伦春自治旗| 长丰县| 疏勒县| 岳普湖县| 托里县| 政和县| 阳谷县| 泰宁县| 军事| 富阳市| 巩义市| 读书| 治县。| 简阳市| 长春市| 舒城县|