You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Note: There's also a mutating ``Swift/Double/round(fractionDigits:rule:)`` functions if you want to change a variable in-place.
115
115
116
+
#### JSON Snake Case Conversion
117
+
118
+
Many APIs return responses using snake_case naming (e.g., `first_name`, `date_of_birth`), while Swift uses camelCase by convention (e.g., `firstName`, `dateOfBirth`). Converting between these naming conventions is a very common need when working with JSON APIs:
119
+
120
+
```swift
121
+
structUser: Codable {
122
+
let firstName: String
123
+
let lastName: String
124
+
let dateOfBirth: Date
125
+
let profileImageUrl: String?
126
+
}
127
+
128
+
funcfetchUser(id: String) asyncthrows-> User {
129
+
let (data, _) =tryawait URLSession.shared.data(from: apiURL)
130
+
131
+
// Automatically converts snake_case JSON to camelCase Swift properties
0 commit comments