All of this together means our views are even more logicless, more direct, and easier to understand. But on Point-Free we like to always ask the question “what’s the point?” so that we can try to convince you that we are getting real benefits from these things and not just describing something that looks cool on the surface, but really isn’t that useful in practice.
And although it can be argued that are views are a bit simpler, it did come at a cost. We had to introduce an all new state struct and action enum for the view, we have to hold onto a whole new object in our views, and we have to provide transformations to construct the view stores. That seems like a lot of extra work to do for each of our views.
So, what’s the point? Is it worth doing this?
We of course think it is! To begin with, if your view is simple or if you don’t think there are any performance concerns in your app or for a particular screen, you can derive your view store by just hitting .view
on your store and you’re done. No extra ceremony necessary!
However, once your application grows in size and use cases, you may find that the view store abstraction is exactly what you need to wrangle in complexity and unlock new capabilities. And to prove this, we are going to implement the feature that all of our PrimeTime users out there have been begging us for: a Mac app 😂.
OK, so there’s maybe not a huge demand out there for a Mac version of our wonderful little counting and prime calculator app, but it will help us demonstrate a key strength in using the view store. We can generalize our business logic so that it isn’t necessarily concerned with platform features, and then use view stores that adapt that generic functionality into a specific platform, like iOS, watchOS, macOS, tvOS or all 4.
And to demonstrate this we are going to build a Mac version of our application that has some subtle differences from the iOS version that we have been building so far. In particular, right now when we ask if the current count is prime we show a modal, but on Mac we will show it as a popover because popovers on macOS are super lightweight and unfortunately are not supported on iPhones. We will also remove the double tap gesture for asking for the “nth prime”, as that type of gesture isn’t super common on Mac.