@@ -161,7 +161,7 @@ extension IndexingIterator: IteratorProtocol, Sequence {
161
161
/// that position.
162
162
///
163
163
/// let text = "Buffalo buffalo buffalo buffalo."
164
- /// if let firstSpace = text.index (of: " ") {
164
+ /// if let firstSpace = text.firstIndex (of: " ") {
165
165
/// print(text[..<firstSpace])
166
166
/// }
167
167
/// // Prints "Buffalo"
@@ -226,7 +226,7 @@ extension IndexingIterator: IteratorProtocol, Sequence {
226
226
/// You can retrieve the same slice using the string's ranged subscript, which
227
227
/// takes a range expression.
228
228
///
229
- /// if let firstSpace = text.index (of: " ") {
229
+ /// if let firstSpace = text.firstIndex (of: " ") {
230
230
/// print(text[..<firstSpace]
231
231
/// // Prints "Buffalo"
232
232
/// }
@@ -373,7 +373,7 @@ public protocol Collection: Sequence where SubSequence: Collection {
373
373
/// safe to use with `endIndex`. For example:
374
374
///
375
375
/// let numbers = [10, 20, 30, 40, 50]
376
- /// if let index = numbers.index (of: 30) {
376
+ /// if let index = numbers.firstIndex (of: 30) {
377
377
/// print(numbers[index ..< numbers.endIndex])
378
378
/// }
379
379
/// // Prints "[30, 40, 50]"
@@ -439,7 +439,7 @@ public protocol Collection: Sequence where SubSequence: Collection {
439
439
/// original collection. This example searches `streetsSlice` for one of the
440
440
/// strings in the slice, and then uses that index in the original array.
441
441
///
442
- /// let index = streetsSlice.index (of: "Evarts")! // 4
442
+ /// let index = streetsSlice.firstIndex (of: "Evarts")! // 4
443
443
/// print(streets[index])
444
444
/// // "Evarts"
445
445
///
@@ -497,7 +497,7 @@ public protocol Collection: Sequence where SubSequence: Collection {
497
497
/// but not including, that index:
498
498
///
499
499
/// let numbers = [10, 20, 30, 40, 50, 60]
500
- /// if let i = numbers.index (of: 40) {
500
+ /// if let i = numbers.firstIndex (of: 40) {
501
501
/// print(numbers.prefix(upTo: i))
502
502
/// }
503
503
/// // Prints "[10, 20, 30]"
@@ -512,7 +512,7 @@ public protocol Collection: Sequence where SubSequence: Collection {
512
512
/// half-open range as the collection's subscript. The subscript notation is
513
513
/// preferred over `prefix(upTo:)`.
514
514
///
515
- /// if let i = numbers.index (of: 40) {
515
+ /// if let i = numbers.firstIndex (of: 40) {
516
516
/// print(numbers[..<i])
517
517
/// }
518
518
/// // Prints "[10, 20, 30]"
@@ -532,7 +532,7 @@ public protocol Collection: Sequence where SubSequence: Collection {
532
532
/// that index:
533
533
///
534
534
/// let numbers = [10, 20, 30, 40, 50, 60]
535
- /// if let i = numbers.index (of: 40) {
535
+ /// if let i = numbers.firstIndex (of: 40) {
536
536
/// print(numbers.suffix(from: i))
537
537
/// }
538
538
/// // Prints "[40, 50, 60]"
@@ -547,7 +547,7 @@ public protocol Collection: Sequence where SubSequence: Collection {
547
547
/// from the index as the collection's subscript. The subscript notation is
548
548
/// preferred over `suffix(from:)`.
549
549
///
550
- /// if let i = numbers.index (of: 40) {
550
+ /// if let i = numbers.firstIndex (of: 40) {
551
551
/// print(numbers[i...])
552
552
/// }
553
553
/// // Prints "[40, 50, 60]"
@@ -568,7 +568,7 @@ public protocol Collection: Sequence where SubSequence: Collection {
568
568
/// including, that index:
569
569
///
570
570
/// let numbers = [10, 20, 30, 40, 50, 60]
571
- /// if let i = numbers.index (of: 40) {
571
+ /// if let i = numbers.firstIndex (of: 40) {
572
572
/// print(numbers.prefix(through: i))
573
573
/// }
574
574
/// // Prints "[10, 20, 30, 40]"
@@ -577,7 +577,7 @@ public protocol Collection: Sequence where SubSequence: Collection {
577
577
/// closed range as the collection's subscript. The subscript notation is
578
578
/// preferred over `prefix(through:)`.
579
579
///
580
- /// if let i = numbers.index (of: 40) {
580
+ /// if let i = numbers.firstIndex (of: 40) {
581
581
/// print(numbers[...i])
582
582
/// }
583
583
/// // Prints "[10, 20, 30, 40]"
@@ -621,8 +621,9 @@ public protocol Collection: Sequence where SubSequence: Collection {
621
621
/// of the collection.
622
622
var count : Int { get }
623
623
624
- // The following requirement enables dispatching for index (of:) when
624
+ // The following requirements enable dispatching for firstIndex (of:) when
625
625
// the element type is Equatable.
626
+
626
627
/// Returns `Optional(Optional(index))` if an element was found
627
628
/// or `Optional(nil)` if an element was determined to be missing;
628
629
/// otherwise, `nil`.
@@ -1067,7 +1068,7 @@ extension Collection where SubSequence == Slice<Self> {
1067
1068
/// print(streetsSlice)
1068
1069
/// // Prints "["Channing", "Douglas", "Evarts"]"
1069
1070
///
1070
- /// let index = streetsSlice.index (of: "Evarts") // 4
1071
+ /// let index = streetsSlice.firstIndex (of: "Evarts") // 4
1071
1072
/// print(streets[index!])
1072
1073
/// // Prints "Evarts"
1073
1074
///
@@ -1180,7 +1181,7 @@ extension Collection {
1180
1181
}
1181
1182
1182
1183
// TODO: swift-3-indexing-model - rename the following to _customIndexOfEquatable(element)?
1183
- /// Customization point for `Collection.index (of:)`.
1184
+ /// Customization point for `Collection.firstIndex (of:)`.
1184
1185
///
1185
1186
/// Define this method if the collection can find an element in less than
1186
1187
/// O(*n*) by exploiting collection-specific knowledge.
@@ -1189,7 +1190,7 @@ extension Collection {
1189
1190
/// `Optional(nil)` if the element was not found, or
1190
1191
/// `Optional(Optional(index))` if an element was found.
1191
1192
///
1192
- /// - Complexity: O(`count`).
1193
+ /// - Complexity: Hopefully less than O(`count`).
1193
1194
@inlinable
1194
1195
public // dispatching
1195
1196
func _customIndexOfEquatableElement( _: Iterator . Element ) -> Index ? ? {
@@ -1402,7 +1403,7 @@ extension Collection {
1402
1403
/// but not including, that index:
1403
1404
///
1404
1405
/// let numbers = [10, 20, 30, 40, 50, 60]
1405
- /// if let i = numbers.index (of: 40) {
1406
+ /// if let i = numbers.firstIndex (of: 40) {
1406
1407
/// print(numbers.prefix(upTo: i))
1407
1408
/// }
1408
1409
/// // Prints "[10, 20, 30]"
@@ -1417,7 +1418,7 @@ extension Collection {
1417
1418
/// half-open range as the collection's subscript. The subscript notation is
1418
1419
/// preferred over `prefix(upTo:)`.
1419
1420
///
1420
- /// if let i = numbers.index (of: 40) {
1421
+ /// if let i = numbers.firstIndex (of: 40) {
1421
1422
/// print(numbers[..<i])
1422
1423
/// }
1423
1424
/// // Prints "[10, 20, 30]"
@@ -1440,7 +1441,7 @@ extension Collection {
1440
1441
/// that index:
1441
1442
///
1442
1443
/// let numbers = [10, 20, 30, 40, 50, 60]
1443
- /// if let i = numbers.index (of: 40) {
1444
+ /// if let i = numbers.firstIndex (of: 40) {
1444
1445
/// print(numbers.suffix(from: i))
1445
1446
/// }
1446
1447
/// // Prints "[40, 50, 60]"
@@ -1455,7 +1456,7 @@ extension Collection {
1455
1456
/// from the index as the collection's subscript. The subscript notation is
1456
1457
/// preferred over `suffix(from:)`.
1457
1458
///
1458
- /// if let i = numbers.index (of: 40) {
1459
+ /// if let i = numbers.firstIndex (of: 40) {
1459
1460
/// print(numbers[i...])
1460
1461
/// }
1461
1462
/// // Prints "[40, 50, 60]"
@@ -1479,7 +1480,7 @@ extension Collection {
1479
1480
/// including, that index:
1480
1481
///
1481
1482
/// let numbers = [10, 20, 30, 40, 50, 60]
1482
- /// if let i = numbers.index (of: 40) {
1483
+ /// if let i = numbers.firstIndex (of: 40) {
1483
1484
/// print(numbers.prefix(through: i))
1484
1485
/// }
1485
1486
/// // Prints "[10, 20, 30, 40]"
@@ -1488,7 +1489,7 @@ extension Collection {
1488
1489
/// closed range as the collection's subscript. The subscript notation is
1489
1490
/// preferred over `prefix(through:)`.
1490
1491
///
1491
- /// if let i = numbers.index (of: 40) {
1492
+ /// if let i = numbers.firstIndex (of: 40) {
1492
1493
/// print(numbers[...i])
1493
1494
/// }
1494
1495
/// // Prints "[10, 20, 30, 40]"
0 commit comments