feat: Apple SDK update for version 18.0.0#118
Conversation
Greptile SummaryThis PR updates the Apple SDK to version 18.0.0, replacing the
Confidence Score: 4/5Safe to merge once the data-extraction fallback in Document and Row is fixed; all other changes are straightforward. The simplification of Sources/AppwriteModels/Document.swift and Sources/AppwriteModels/Row.swift — both have the same data-extraction fallback regression. Important Files Changed
Reviews (2): Last reviewed commit: "chore: update Apple SDK to 18.0.0" | Re-trigger Greptile |
| return try! JSONSerialization.data(withJSONObject: [:] as [String: Any], options: []) | ||
| } | ||
| }()) | ||
| metadata: (map["metadata"] as? [String: Any] ?? [:]).mapValues { AnyCodable($0) } |
There was a problem hiding this comment.
When
map["metadata"] is absent or nil, the ?? [:] fallback converts it to an empty dictionary, so metadata is always non-nil on the from(map:) path. The init(from decoder:) path uses decodeIfPresent, which correctly returns nil for a missing key. Any caller checking presence.metadata != nil (or using metadata in an if let / guard let) will always see a truthy value when the object was built via from(map:), even when the server returned no metadata.
| metadata: (map["metadata"] as? [String: Any] ?? [:]).mapValues { AnyCodable($0) } | |
| metadata: (map["metadata"] as? [String: Any]).map { $0.mapValues { AnyCodable($0) } } |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| return try! JSONSerialization.data(withJSONObject: [:] as [String: Any], options: []) | ||
| } | ||
| }()) | ||
| data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map["data"] as? [String: Any] ?? map, options: [])) |
There was a problem hiding this comment.
The new fallback
map["data"] as? [String: Any] ?? map silently substitutes the entire parent map whenever map["data"] exists but is not a dictionary (e.g., a JSON array). In the previous code, JSONSerialization.isValidJSONObject(raw) handled that branch correctly and would still serialize the actual data value. Now, if a server ever returns an array-typed data, the entire document map (including $id, $collectionId, etc.) is passed to JSONDecoder instead — either producing a wrong T silently or crashing the try!.
| data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map["data"] as? [String: Any] ?? map, options: [])) | |
| data: try! JSONDecoder().decode(T.self, from: { | |
| let raw = map["data"] | |
| if let dict = raw as? [String: Any] { | |
| return try! JSONSerialization.data(withJSONObject: dict, options: []) | |
| } else if let raw = raw, JSONSerialization.isValidJSONObject(raw) { | |
| return try! JSONSerialization.data(withJSONObject: raw, options: []) | |
| } else { | |
| return try! JSONSerialization.data(withJSONObject: [:] as [String: Any], options: []) | |
| } | |
| }()) |
| return try! JSONSerialization.data(withJSONObject: [:] as [String: Any], options: []) | ||
| } | ||
| }()) | ||
| data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map["data"] as? [String: Any] ?? map, options: [])) |
There was a problem hiding this comment.
Same regression as
Document.swift: the ?? map fallback is reached both when data is absent and when data is present but is not a [String: Any] (e.g., an array). In the latter case the entire row map is passed to JSONDecoder instead of the actual data payload, silently decoding wrong data or crashing. The previous implementation correctly handled non-dict JSON via JSONSerialization.isValidJSONObject.
| data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map["data"] as? [String: Any] ?? map, options: [])) | |
| data: try! JSONDecoder().decode(T.self, from: { | |
| let raw = map["data"] | |
| if let dict = raw as? [String: Any] { | |
| return try! JSONSerialization.data(withJSONObject: dict, options: []) | |
| } else if let raw = raw, JSONSerialization.isValidJSONObject(raw) { | |
| return try! JSONSerialization.data(withJSONObject: raw, options: []) | |
| } else { | |
| return try! JSONSerialization.data(withJSONObject: [:] as [String: Any], options: []) | |
| } | |
| }()) |
This PR contains updates to the Apple SDK for version 18.0.0.