Why do enums have computed properties but not stored properties in Swift?
I am new to Swift and just came across this in the documentation:
Computed properties are provided by classes, structures, and enumerations. Stored
properties are provided only by classes and structures.
Please provide technical reason for these ??
Static properties are different from a property on an instance of a object or struct or enum. With objects and structs, you have discrete instances of those entities. With enums, you don't, but you still have the type itself. Think of it this way: the type is kind of like a cookie cutter, which obviously is a real object. Objects and structs are like cookies made using the cutter: each one is also a real and independent object, and you can decorate each one differently (instance properties—both stored and computed). You can also bend the cookie cutter into a different shape (static properties).
With enums, all you have is the cookie cutter. You can take photographs of it and share them around, but that's it. There are no "real" instances of an enum. You can still bend the cookie cutter around (static properties), but you have no cookies to decorate. However, you can imagine what the cookies would look like and make plans based on it. Those are get-only computed properties, which you are allowed to use in an enum.
Sorry if this is a little hard to explain, but I hope I'm making things a little clearer for you 🙂