@@ -71,13 +71,31 @@ public class OptimizelyJSON: NSObject {
71
71
///
72
72
/// If JSON Data is {"k1":true, "k2":{"k3":"v3"}}
73
73
///
74
- /// Set jsonPath to "k2" to access {"k3":"v3"} or set it to "k2.k3" to access "v3"
75
- /// Set it to nil or empty to access the entire JSON data.
74
+ /// Set jsonPath to "k2" to access {"k3":"v3"} or set it to "k2.k3" to access "v3".
75
+ /// Set it to nil or empty to access the entire JSON data. See more examples below:
76
+ ///
77
+ ///
78
+ /// struct Student: Decodable {
79
+ /// let name: String
80
+ /// let age: Int
81
+ /// let address: Address
82
+ /// }
83
+ ///
84
+ /// struct Address: Decodable {
85
+ /// let state: String
86
+ /// let emails: [String]
87
+ /// }
88
+ ///
89
+ /// let student: Student? = optimizelyJSON.getValue(jsonPath: nil)
90
+ /// let address: Address? = optimizelyJSON.getValue(jsonPath: "address")
91
+ /// let name: String? = optimizelyJSON.getValue(jsonPath: "name")
92
+ /// let emails: [String]? = optimizelyJSON.getValue(jsonPath: "address.emails")
93
+ ///
76
94
///
77
95
/// - Parameters:
78
96
/// - jsonPath: Key path for the value.
79
97
/// - Returns: Value if decoded successfully
80
- public func getValue< T: Decodable > ( jsonPath: String ? = nil ) -> T ? {
98
+ public func getValue< T: Decodable > ( jsonPath: String ? ) -> T ? {
81
99
func handler( value: Any ) -> T ? {
82
100
guard JSONSerialization . isValidJSONObject ( value) else {
83
101
// Try and typecast value to required return type
@@ -102,8 +120,26 @@ public class OptimizelyJSON: NSObject {
102
120
///
103
121
/// If JSON Data is {"k1":true, "k2":{"k3":"v3"}}
104
122
///
105
- /// Set jsonPath to "k2" to access {"k3":"v3"} or set it to "k2.k3" to access "v3"
106
- /// Set it to nil or empty to access the entire JSON data.
123
+ /// Set jsonPath to "k2" to access {"k3":"v3"} or set it to "k2.k3" to access "v3".
124
+ /// Set it to nil or empty to access the entire JSON data. See more examples below:
125
+ ///
126
+ ///
127
+ /// struct Student: Decodable {
128
+ /// let name: String
129
+ /// let age: Int
130
+ /// let address: Address
131
+ /// }
132
+ ///
133
+ /// struct Address: Decodable {
134
+ /// let state: String
135
+ /// let emails: [String]
136
+ /// }
137
+ ///
138
+ /// let student: Student? = optimizelyJSON.getValue(jsonPath: nil)
139
+ /// let address: Address? = optimizelyJSON.getValue(jsonPath: "address")
140
+ /// let name: String? = optimizelyJSON.getValue(jsonPath: "name")
141
+ /// let emails: [String]? = optimizelyJSON.getValue(jsonPath: "address.emails")
142
+ ///
107
143
///
108
144
/// - Parameters:
109
145
/// - jsonPath: Key path for the value.
0 commit comments