Skip to content

Can we flatten structs? #24

Open
Open
@helje5

Description

@helje5

Looks like SwiftData flattens Codable structure into own table columns vs storing them as JSON.
Presumably to be able to run queries against such.

E.g.

@Model class Person {
  struct Address: Codable {
    var street: String
    var city: String
  }
  var privateAddress : Address
}

Even though the property is just one in the model, I think it ends up in separate columns in SQLite. Presumably to allow this:

#Predicate {
  $0.privateAddress.street = "XYZ"
}

Which seems valuable?

Not sure how we would hook that up in Core Data yet, I'd guess the Entity would need to get attributes for those.

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