77
88import Foundation
99
10- /**
11- A type-erased `Codable` value.
12-
13- The `AnyCodable` type forwards encoding and decoding responsibilities
14- to an underlying value, hiding its specific underlying type.
15-
16- You can encode or decode mixed-type values in dictionaries
17- and other collections that require `Encodable` or `Decodable` conformance
18- by declaring their contained type to be `AnyCodable`.
19-
20- - SeeAlso: `AnyEncodable`
21- - SeeAlso: `AnyDecodable`
22- */
10+ /// A type-erased `Codable` value.
11+ ///
12+ /// The `AnyCodable` type forwards encoding and decoding responsibilities
13+ /// to an underlying value, hiding its specific underlying type.
14+ ///
15+ /// You can encode or decode mixed-type values in dictionaries
16+ /// and other collections that require `Encodable` or `Decodable` conformance
17+ /// by declaring their contained type to be `AnyCodable`.
18+ ///
19+ /// - SeeAlso: `AnyEncodable`
20+ /// - SeeAlso: `AnyDecodable`
2321@frozen
2422public struct AnyCodable : Codable {
2523 public let value : Any
@@ -35,47 +33,47 @@ extension AnyCodable: Equatable {
3533 public static func == ( lhs: AnyCodable , rhs: AnyCodable ) -> Bool {
3634 switch ( lhs. value, rhs. value) {
3735 case is ( Void , Void ) :
38- return true
36+ true
3937 case ( let lhs as Bool , let rhs as Bool ) :
40- return lhs == rhs
38+ lhs == rhs
4139 case ( let lhs as Int , let rhs as Int ) :
42- return lhs == rhs
40+ lhs == rhs
4341 case ( let lhs as Int8 , let rhs as Int8 ) :
44- return lhs == rhs
42+ lhs == rhs
4543 case ( let lhs as Int16 , let rhs as Int16 ) :
46- return lhs == rhs
44+ lhs == rhs
4745 case ( let lhs as Int32 , let rhs as Int32 ) :
48- return lhs == rhs
46+ lhs == rhs
4947 case ( let lhs as Int64 , let rhs as Int64 ) :
50- return lhs == rhs
48+ lhs == rhs
5149 case ( let lhs as UInt , let rhs as UInt ) :
52- return lhs == rhs
50+ lhs == rhs
5351 case ( let lhs as UInt8 , let rhs as UInt8 ) :
54- return lhs == rhs
52+ lhs == rhs
5553 case ( let lhs as UInt16 , let rhs as UInt16 ) :
56- return lhs == rhs
54+ lhs == rhs
5755 case ( let lhs as UInt32 , let rhs as UInt32 ) :
58- return lhs == rhs
56+ lhs == rhs
5957 case ( let lhs as UInt64 , let rhs as UInt64 ) :
60- return lhs == rhs
58+ lhs == rhs
6159 case ( let lhs as Float , let rhs as Float ) :
62- return lhs == rhs
60+ lhs == rhs
6361 case ( let lhs as Double , let rhs as Double ) :
64- return lhs == rhs
62+ lhs == rhs
6563 case ( let lhs as String , let rhs as String ) :
66- return lhs == rhs
64+ lhs == rhs
6765 case ( let lhs as [ String : AnyCodable ] , let rhs as [ String : AnyCodable ] ) :
68- return lhs == rhs
66+ lhs == rhs
6967 case ( let lhs as [ AnyCodable ] , let rhs as [ AnyCodable ] ) :
70- return lhs == rhs
68+ lhs == rhs
7169 case ( let lhs as [ String : Any ] , let rhs as [ String : Any ] ) :
72- return NSDictionary ( dictionary: lhs) == NSDictionary ( dictionary: rhs)
70+ NSDictionary ( dictionary: lhs) == NSDictionary ( dictionary: rhs)
7371 case ( let lhs as [ Any ] , let rhs as [ Any ] ) :
74- return NSArray ( array: lhs) == NSArray ( array: rhs)
72+ NSArray ( array: lhs) == NSArray ( array: rhs)
7573 case is ( NSNull , NSNull ) :
76- return true
74+ true
7775 default :
78- return false
76+ false
7977 }
8078 }
8179}
@@ -84,11 +82,11 @@ extension AnyCodable: CustomStringConvertible {
8482 public var description : String {
8583 switch value {
8684 case is Void :
87- return String ( describing: nil as Any ? )
85+ String ( describing: nil as Any ? )
8886 case let value as CustomStringConvertible :
89- return value. description
87+ value. description
9088 default :
91- return String ( describing: value)
89+ String ( describing: value)
9290 }
9391 }
9492}
@@ -97,9 +95,9 @@ extension AnyCodable: CustomDebugStringConvertible {
9795 public var debugDescription : String {
9896 switch value {
9997 case let value as CustomDebugStringConvertible :
100- return " AnyCodable( \( value. debugDescription) ) "
98+ " AnyCodable( \( value. debugDescription) ) "
10199 default :
102- return " AnyCodable( \( description) ) "
100+ " AnyCodable( \( description) ) "
103101 }
104102 }
105103}
@@ -113,7 +111,6 @@ extension AnyCodable: ExpressibleByStringInterpolation {}
113111extension AnyCodable : ExpressibleByArrayLiteral { }
114112extension AnyCodable : ExpressibleByDictionaryLiteral { }
115113
116-
117114extension AnyCodable : Hashable {
118115 public func hash( into hasher: inout Hasher ) {
119116 switch value {
0 commit comments