Skip to content

[Feature]: Support attribute validation rules in @Attribute (min/max values, regex, dates) #19

Description

@malhal

Area

PersistentModel or model macros

Problem or use case

One of the main reason for sticking with Core Data over SwiftData is model validation, that is when attempting to save the context validation errors might be thrown for any changed models that break their validation rules. I think it would be a great feature to bring the validation aspect of Xcode's Core Data model editor (see screenshot) into CDE's model code.

Image

Proposed shape

The feature could be implemented with additional params in @Attribute, e.g. for a String attribute:

@Attribute(persistentName: "name", minLength: 1, regEx: /.*\S.*/)
var title: String = ""

Similarly for an Int attribute:

@Attribute(persistentName: "count", min: 0, max: 255)
var count: Int = 0

Similarly for Date attribute:

@Attribute(
  persistentName: "timestamp",
  minDate: .distantPast,
  maxDate: .distantFuture
)
var timestamp: Date = Date()

Alternatives considered

No response

Compatibility notes

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions