Skip to content

Issue with @FormField Property Wrapper and @Observable in viewModel in swiftUI iOS 17 #23

@avasveliya

Description

@avasveliya

We recently updated our view model from using @observableobject to @observable. The original code, which used ObservableObject, was working as expected and the latest value in timeZoneInput was correctly captured.

Old Code:

final class DummyClassViewModel: ObservableObject { }

@FormField(validator: {
    DropDownValidator<RoleDummy>(message: "Selection is required")
})
var timeZoneInput: RoleDummy = RoleDummy.empty
lazy var timeZoneInputValidation = _timeZoneInputInput.validation(manager: formManager)

Now, we have changed the class to use the @observable macro, which is provided by the appple , as shown below:

New Code:

@Observable
final class DummyClassViewModel { }

However, after this change, we are encountering the following issue:

Error:
Property wrapper cannot be applied to a computed property.

Solution Attempt:
We tried adding @ObservationIgnored to the @formfield property wrapper, but as the name suggests, it causes the timeZoneInput to not receive the latest value.

Here is the code causing the issue:

@FormField(validator: {
    NonEmptyValidator(message: "This field is required.")
})
var timeZoneInput: RoleDummy = RoleDummy.empty

Expected Behavior:
The timeZoneInput should be able to work with the property wrapper @formfield and retain the latest value as expected, without encountering the Property wrapper cannot be applied to a computed property error.

Could you please take a look at this issue and provide a solution or suggest a workaround? I have attached a screenshot for your reference.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions