Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

Stop using Codable everywhere.

DEV Community·Mok5ha·20 days ago
#Xs1olNbC
Reading 0:00
15s threshold

You’ve been over-engineering your Swift models. “Should this model be Decodable or Codable? Am I doing this wrong?” — Here's how to pick the right one. Swift doesn’t provide a single “JSON protocol.” It gives you three, each with a specific responsibility Most networking code only needs Decodable When your app fetches data and displays it, data flows one way — from the server into your models. The Decodable conformance is a signal to anyone reading this code: this model is read-only by design. You don’t need Codable here, just in case. struct Article : Decodable { let id : Int let title : String let publishedAt : Date let author : Author } Enter fullscreen mode Exit fullscreen mode Use Codable when data moves in both directions Two situations make Codable the right call: You’re sending data back to a server A request body going out as JSON, a form payload, a PUT with updated fields — anything where your Swift type needs to become JSON.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More