@@ -309,7 +309,7 @@ public struct Mirror {
309
309
/// `subject` is not a class instance. The default is `.generated`.
310
310
public init < Subject> (
311
311
_ subject: Subject ,
312
- children: DictionaryLiteral < String , Any > ,
312
+ children: KeyValuePairs < String , Any > ,
313
313
displayStyle: DisplayStyle ? = nil ,
314
314
ancestorRepresentation: AncestorRepresentation = . generated
315
315
) {
@@ -464,25 +464,25 @@ extension Mirror {
464
464
465
465
/// A lightweight collection of key-value pairs.
466
466
///
467
- /// Use a `DictionaryLiteral ` instance when you need an ordered collection of
467
+ /// Use a `KeyValuePairs ` instance when you need an ordered collection of
468
468
/// key-value pairs and don't require the fast key lookup that the
469
469
/// `Dictionary` type provides. Unlike key-value pairs in a true dictionary,
470
- /// neither the key nor the value of a `DictionaryLiteral ` instance must
470
+ /// neither the key nor the value of a `KeyValuePairs ` instance must
471
471
/// conform to the `Hashable` protocol.
472
472
///
473
- /// You initialize a `DictionaryLiteral ` instance using a Swift dictionary
473
+ /// You initialize a `KeyValuePairs ` instance using a Swift dictionary
474
474
/// literal. Besides maintaining the order of the original dictionary literal,
475
- /// `DictionaryLiteral ` also allows duplicates keys. For example:
475
+ /// `KeyValuePairs ` also allows duplicates keys. For example:
476
476
///
477
- /// let recordTimes: DictionaryLiteral = ["Florence Griffith-Joyner": 10.49,
477
+ /// let recordTimes: KeyValuePairs = ["Florence Griffith-Joyner": 10.49,
478
478
/// "Evelyn Ashford": 10.76,
479
479
/// "Evelyn Ashford": 10.79,
480
480
/// "Marlies Gohr": 10.81]
481
481
/// print(recordTimes.first!)
482
482
/// // Prints "("Florence Griffith-Joyner", 10.49)"
483
483
///
484
484
/// Some operations that are efficient on a dictionary are slower when using
485
- /// `DictionaryLiteral `. In particular, to find the value matching a key, you
485
+ /// `KeyValuePairs `. In particular, to find the value matching a key, you
486
486
/// must search through every element of the collection. The call to
487
487
/// `firstIndex(where:)` in the following example must traverse the whole
488
488
/// collection to find the element that matches the predicate:
@@ -499,67 +499,70 @@ extension Mirror {
499
499
/// Dictionary Literals as Function Parameters
500
500
/// ------------------------------------------
501
501
///
502
- /// When calling a function with a `DictionaryLiteral ` parameter, you can pass
502
+ /// When calling a function with a `KeyValuePairs ` parameter, you can pass
503
503
/// a Swift dictionary literal without causing a `Dictionary` to be created.
504
504
/// This capability can be especially important when the order of elements in
505
505
/// the literal is significant.
506
506
///
507
507
/// For example, you could create an `IntPairs` structure that holds a list of
508
508
/// two-integer tuples and use an initializer that accepts a
509
- /// `DictionaryLiteral ` instance.
509
+ /// `KeyValuePairs ` instance.
510
510
///
511
511
/// struct IntPairs {
512
512
/// var elements: [(Int, Int)]
513
513
///
514
- /// init(_ elements: DictionaryLiteral <Int, Int>) {
514
+ /// init(_ elements: KeyValuePairs <Int, Int>) {
515
515
/// self.elements = Array(elements)
516
516
/// }
517
517
/// }
518
518
///
519
519
/// When you're ready to create a new `IntPairs` instance, use a dictionary
520
520
/// literal as the parameter to the `IntPairs` initializer. The
521
- /// `DictionaryLiteral ` instance preserves the order of the elements as
521
+ /// `KeyValuePairs ` instance preserves the order of the elements as
522
522
/// passed.
523
523
///
524
524
/// let pairs = IntPairs([1: 2, 1: 1, 3: 4, 2: 1])
525
525
/// print(pairs.elements)
526
526
/// // Prints "[(1, 2), (1, 1), (3, 4), (2, 1)]"
527
527
@_fixed_layout // FIXME(sil-serialize-all)
528
- public struct DictionaryLiteral < Key, Value> : ExpressibleByDictionaryLiteral {
529
- /// Creates a new `DictionaryLiteral ` instance from the given dictionary
528
+ public struct KeyValuePairs < Key, Value> : ExpressibleByDictionaryLiteral {
529
+ /// Creates a new `KeyValuePairs ` instance from the given dictionary
530
530
/// literal.
531
531
///
532
532
/// The order of the key-value pairs is kept intact in the resulting
533
- /// `DictionaryLiteral ` instance.
533
+ /// `KeyValuePairs ` instance.
534
534
public init ( dictionaryLiteral elements: ( Key , Value ) ... ) {
535
535
self . _elements = elements
536
536
}
537
537
@usableFromInline // FIXME(sil-serialize-all)
538
538
internal let _elements : [ ( Key , Value ) ]
539
539
}
540
540
541
- /// `Collection` conformance that allows `DictionaryLiteral` to
541
+ @available ( swift, deprecated: 5.0 , renamed: " KeyValuePairs " )
542
+ public typealias DictionaryLiteral < Key, Value> = KeyValuePairs < Key , Value >
543
+
544
+ /// `Collection` conformance that allows `KeyValuePairs` to
542
545
/// interoperate with the rest of the standard library.
543
- extension DictionaryLiteral : RandomAccessCollection {
546
+ extension KeyValuePairs : RandomAccessCollection {
544
547
public typealias Indices = Range < Int >
545
548
546
549
/// The position of the first element in a nonempty collection.
547
550
///
548
- /// If the `DictionaryLiteral ` instance is empty, `startIndex` is equal to
551
+ /// If the `KeyValuePairs ` instance is empty, `startIndex` is equal to
549
552
/// `endIndex`.
550
553
@inlinable // FIXME(sil-serialize-all)
551
554
public var startIndex : Int { return 0 }
552
555
553
556
/// The collection's "past the end" position---that is, the position one
554
557
/// greater than the last valid subscript argument.
555
558
///
556
- /// If the `DictionaryLiteral ` instance is empty, `endIndex` is equal to
559
+ /// If the `KeyValuePairs ` instance is empty, `endIndex` is equal to
557
560
/// `startIndex`.
558
561
@inlinable // FIXME(sil-serialize-all)
559
562
public var endIndex : Int { return _elements. endIndex }
560
563
561
564
// FIXME(ABI)#174 (Type checker): a typealias is needed to prevent <rdar://20248032>
562
- /// The element type of a `DictionaryLiteral `: a tuple containing an
565
+ /// The element type of a `KeyValuePairs `: a tuple containing an
563
566
/// individual key-value pair.
564
567
public typealias Element = ( key: Key , value: Value )
565
568
0 commit comments