File tree 3 files changed +17
-3
lines changed
3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ import UIKit
36
36
/// each category is a breadcrumb in list form
37
37
public var categories : [ String ] ?
38
38
39
+ /// data fields for this product
40
+ public var dataFields : [ AnyHashable : Any ] ?
41
+
39
42
/// Creates a `CommerceItem` with the specified properties
40
43
///
41
44
/// - Parameters:
@@ -58,7 +61,8 @@ import UIKit
58
61
description: String ? = nil ,
59
62
url: String ? = nil ,
60
63
imageUrl: String ? = nil ,
61
- categories: [ String ] ? = nil ) {
64
+ categories: [ String ] ? = nil ,
65
+ dataFields: [ AnyHashable : Any ] ? = nil ) {
62
66
self . id = id
63
67
self . name = name
64
68
self . price = price
@@ -68,6 +72,7 @@ import UIKit
68
72
self . url = url
69
73
self . imageUrl = imageUrl
70
74
self . categories = categories
75
+ self . dataFields = dataFields
71
76
}
72
77
73
78
/// A `Dictionary` representation of this item
@@ -99,6 +104,10 @@ import UIKit
99
104
dictionary [ JsonKey . CommerceItem. categories] = categories
100
105
}
101
106
107
+ if let dataFields = dataFields {
108
+ dictionary [ JsonKey . CommerceItem. dataFields] = dataFields
109
+ }
110
+
102
111
return dictionary
103
112
}
104
113
}
Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ enum JsonKey {
170
170
static let imageUrl = " imageUrl "
171
171
static let url = " url "
172
172
static let categories = " categories "
173
+ static let dataFields = " dataFields "
173
174
}
174
175
175
176
enum Device {
Original file line number Diff line number Diff line change @@ -28,7 +28,9 @@ class CommerceItemTests: XCTestCase {
28
28
url: " stand-alone-complex " ,
29
29
imageUrl: " laughing-man " ,
30
30
categories: [ " section 9 " ,
31
- " personnel transport " ] ) . toDictionary ( )
31
+ " personnel transport " ] ,
32
+ dataFields: [ " color " : " yellow " ,
33
+ " count " : 8 ] ) . toDictionary ( )
32
34
33
35
let expected : [ AnyHashable : Any ] = [ " id " : " THINKTANK " ,
34
36
" name " : " Tachikoma " ,
@@ -39,7 +41,9 @@ class CommerceItemTests: XCTestCase {
39
41
" url " : " stand-alone-complex " ,
40
42
" imageUrl " : " laughing-man " ,
41
43
" categories " : [ " section 9 " ,
42
- " personnel transport " ] ]
44
+ " personnel transport " ] ,
45
+ " dataFields " : [ " color " : " yellow " ,
46
+ " count " : 8 ] ]
43
47
44
48
XCTAssertEqual ( NSDictionary ( dictionary: itemDictionary) , NSDictionary ( dictionary: expected) )
45
49
}
You can’t perform that action at this time.
0 commit comments