Should I use Classes or Structs in a YapDatabase?

41 Views Asked by At

I have a simple data structure for storing a User:

struct User{
     let id: String
     var name: String
}

I'm confused as to whether I should be using a Struct or a Class. I've consulted Apple's documentation:

In an app that consults a remote database, for example, an instance's identity may be fully owned by an external entity and communicated by an identifier. If the consistency of an app's models is stored on a server, you can model records as structures with identifiers.

Local changes to model types like PenPalRecord are useful. For example, an app might recommend multiple different penpals in response to user feedback. Because the PenPalRecord structure doesn't control the identity of the underlying database records, there's no risk that the changes made to local PenPalRecord instances accidentally change values in the database.

This would suggest using a struct, since I wouldn't want to accidentally modify the model in the database, the YapDatabase being a a key/value store. YapDatabase is clear that you can store both Structs and Classes. Yet most of their documentation seems to suggest using a Class.

Any thoughts?

0

There are 0 best solutions below