Using struct instead of class


So the Checklists tutorial uses classes for the data models, shouldn’t you use structs instead? Structs are quite powerful in swift now and from what I have been reading, classes should be used mostly if your model requires reference types or inheritance, which is not the case (although deinit doesn’t seem to be present in struct).



It uses classes because the objects in the data model are reference types. A checklist is a unique thing that has an identity of its own.

Think about it this way. You have two lists with the same items in it: are they the same list or are they two different lists? (If they are two different lists, how do you tell them apart if you would be using structs?)

I’m not saying you cannot use structs here, but in my mind classes map to the underlying model better.

Nice answer. I originally didn’t consider the lists as unique.