79797936

Date: 2025-10-23 14:50:57
Score: 0.5
Natty:
Report link

Thanks to @Sweeper for pointing me to @Transient.

The following code works both my example, and real project:

import SwiftData

struct Foo {
    var name: String
}

@Model
final class Bar {
    var id: String
    var name: String
    
    @Transient
    var foo: Foo = .init(name: "")
    
    init(id: String, name: String) {
        self.id = id
        self.name = name
    }
    
    func changeFoo(newName: String) {
        foo.name = newName
    }
}
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Has code block (-0.5):
  • User mentioned (1): @Sweeper
  • Self-answer (0.5):
  • High reputation (-1):
Posted by: koen