May 29, 2022
I decided to divert from my original plan of jumping into CoreData.
Instead, I decided to revamp one of the main systems in the app, much as I did with Drink Types.
Liquidus allows viewing data across a day, week, month, half-year, and year. Prior I’ve used Date
for a day and an hour, [Date]
for a week and a month, and [[Date]]
for half-years and years.
Each of these now has separate classes; Hour
, Day
, Week
, Month
, HalfYear
, and Year
. All of these classes conform to a protocol
called DatesProtocol
.
This protocol requires two initializers: one for the current day and one that takes in a Date
. It also requires, a UUID, a description, and an accessibility description. Both descriptions are fairly similar with some variations. It also has a data property.
This property is assigned an associatedtype
in the protocol
. This means, that when creating a conforming class or struct, you can choose what this data type is. For instance, an Hour
and Day
uses a Date
, a Week
and a Month
uses a [Day]
, a HalfYear
uses a [Week]
, and a Year
uses a [Month]
. Yet, these classes all conform to DatesProtocol
.
Additionally, HalfYear
and Year
have a superclass that supplies methods both classes use to generate their properties since that’s how I went about it in the old system.
With these created, I updated the DrinkModel
, all the views, the widget, the intent, and the unit tests.
What was a little problematic was updating Day
, Week
, Month
, etc. in the view and expecting the view to update. Just supplanting wouldn’t update the view with @Binding
and @State
.
After doing some looking around online, I found that I had to create a boolean trigger @State
/@Binding
The parent-most view would hold the @State
variable, and the sub-views would get a @Binding
. After some action occurred, I had to toggle the variable, from true
to false
or vice versa, or update another @State
variable.
Another thing I did alongside this was updating the documentation throughout the app. All of the methods have blatant parameter and return methods. Classes, Structs, and their properties have documentation too, with the exception of views. More information about documentation can be found here.
You can also get your documentation to show in Xcode’s documentation view. All you have to do is, in the menu bar, go to Product > Build Documentation. It’ll create the documentation based on what you provide.