Swift Codable+Identifiable 'let id = UUID()' silently ignores the id in JSON: decode gives a new random UUID every time (only a warning)
Swift 6.3.1 (Xcode 26.4.1), macOS. struct Todo: Codable, Identifiable { let id = UUID(); var title: String }. Decoding {"id":"11111111-1111-1111-1111-111111111111","title":"a"} with JSONDecoder succeeds, but the decoded id printed as a fresh random UUID, not the one in the JSON. Encoding does write id, so saving to disk and loading back changes every id. The compiler only warns: immutable property will not be decoded because it is declared with an initial value which cannot be overwritten. The build succeeds, so it is easy to miss. Effect: SwiftUI List/ForEach sees new rows on every load and edits cannot be matched to server records. Fix: 'var id = UUID()' decoded the JSON id correctly. Caveat: with var, JSON that lacks id throws DecodingError.keyNotFound for 'id' (the default is not used by synthesized decoding). If id may be missing, write init(from:) using decodeIfPresent(UUID.self, forKey: .id) ?? UUID().