Context
I’ve a easy Kind utilizing the MVVM structure. Nevertheless, I encountered an issue with this implementation.
Drawback: I’ve a
CustomForm
which updates aTextual content
relying onisValid
ofFormViewModel
outlined inCustomFormObservable
. Nevertheless, when getting into a reputation, theTextual content
doesn’t change to “Save”. I do perceive that that is because of the truth, thatisValid
is just not marked as@Revealed
, nonetheless, I am unable to determine a workaround with the given structure beneath.
Minimal Reproducible Instance (MRE)
@objc(Entity) public class Entity: NSManagedObject {
@NSManaged public var title: String
}
protocol CustomFormObservable: ObservableObject {
var isValid: Bool { get }
}
class FormViewModel: CustomFormObservable {
@Revealed var entity = Entity(context: ...)
var isValid: Bool { !entity.title.isEmpty }
}
struct Kind: View {
@StateObject personal var formVM = FormViewModel()
var physique: some View {
CustomForm(formVM: formVM) {
EditNameSection(entity: formVM.entity)
}
}
}
struct CustomForm<CFO: CustomFormObservable>: View {
@ObservedObject var customFormVM: CFO
var physique: some View {
Button(motion: { ... }) { Textual content(customFormVM.isValid ? "Save" : "Lacking") }
}
}
struct DetailForm: View {
@ObservedObject var entity: Entity
var physique: some View {
TextField("Title", textual content: $entity.title)
}
}
Query
- Since I can not mark a
ComputedProperty
likeisValid
as@Revealed
, how can I clear up this downside?