@@ -71,13 +71,31 @@ public class OptimizelyJSON: NSObject {
7171 ///
7272 /// If JSON Data is {"k1":true, "k2":{"k3":"v3"}}
7373 ///
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+ ///
7694 ///
7795 /// - Parameters:
7896 /// - jsonPath: Key path for the value.
7997 /// - Returns: Value if decoded successfully
80- public func getValue< T: Decodable > ( jsonPath: String ? = nil ) -> T ? {
98+ public func getValue< T: Decodable > ( jsonPath: String ? ) -> T ? {
8199 func handler( value: Any ) -> T ? {
82100 guard JSONSerialization . isValidJSONObject ( value) else {
83101 // Try and typecast value to required return type
@@ -102,8 +120,26 @@ public class OptimizelyJSON: NSObject {
102120 ///
103121 /// If JSON Data is {"k1":true, "k2":{"k3":"v3"}}
104122 ///
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+ ///
107143 ///
108144 /// - Parameters:
109145 /// - jsonPath: Key path for the value.
0 commit comments