Vision Pro Goes on Sale, No More Protocols, StoreKit Testing
- #SwiftUI
- #Xcode
• 4 min read
Are you tired of hearing about MVC and MVVM protocols? Today, we'll delve into the exciting world of StoreKit 2 and how to build apps for visionOS. I'm Serhii Butenko, an engineer at CleanMyMac, and we're going to explore the latest developments in iOS and macOS.
You don't need protocols
You don't always need protocols. They can be overrated and sometimes excessive. Often, you can effectively use closures, structures, or enums instead. Consider this scenario: you need to pass a single call. Opting for a protocol means naming it, adding a function, passing the dependency, and implementing the protocol. Then, you must create a mock for testing and implement the protocol there too. This approach leads to excessive code and complexity. A simpler solution? Just pass a closure, and you're all set.
This principle also applies to protocols that describe a data structure. In many cases, it's more straightforward to use structures directly, particularly for a basic model with no logic.
As you can see, there are situations where protocols are unnecessary, but we can't do without your support. Learn more about this topic here.
Container pattern in SwiftUI
Everyone seems tired of MVC, MVVM, and other patterns. Plus, SwiftUI’s approach has evolved significantly. Declarative UI shares many similarities across platforms. This article provides an example of using the Container pattern from React, which separates data retrieval from UI rendering.
However, we eventually circle back to MVVM, where the view model is implemented as a View, complicating testing.
Vision Pro goes on sale
Vision Pro will be available for purchase starting February 2nd, initially only in the US, and priced from 3500 USD. It's hard to imagine the markups in other regions, especially in the initial weeks. What do you think the price will be in your country? Share your guesses in the comments. In true Apple style, a separate travel case is available for just 199 USD.
Moving beyond the dry facts, journalists had the opportunity to test Vision Pro before its release, sharing their experiences with the device's fit and adjustments. You might need additional lenses or different padding for comfort. A common observation was its heavy feel after 15 minutes of use. Maybe, like with FPV, it requires some time to adapt.
Vision Pro already supports text input in several ways:
- By voice
- Typing on a virtual keyboard
- Selecting letters with your eyes and confirming with gestures
Journalists praised the precision of the eye and gesture tracking, but coding with this device still seems challenging. The meditation/mindfulness app is a highlight, offering immersive experiences in a forest or by the sea.
However, in unexpected news, Netflix, Spotify, and YouTube will NOT be developing apps for visionOS and will disable adapted iPad apps. This is disappointing for those eagerly anticipating the device, leading some to consider waiting for the next version.
Apple has gone a long way from the first Macintosh that turns 40 this year, earning it the title of a millennial. By the way, we have one in our MacPaw office!
Q&A: Building apps for visionOS
How do you develop apps for visionOS? Fortunately, Apple has released a Q&A on this topic. The article provides instructions on interacting with elements using gestures, choosing between windows and immersive space, and offers insights on element layout. However, the guide reads more like a product review than a comprehensive manual. If you've already adapted your app for visionOS, you're likely familiar with these details. If not, you might find some aspects unclear.
StoreKit testing in Swift
StoreKit 2 facilitates testing purchases in a simulator and writing unit tests for purchase flows using the SKTestSession class in the StoreKitTest framework. You can create a session, specify a store kit file with products, and test all your execution scenarios. It provides several methods for managing purchases, including buying a product, processing returns, or simulating failed payments.
I highly recommend adopting StoreKit 2 and writing tests. A notable feature is that StoreKit 2 is entirely built on the async-await API, requiring you to wrap everything in Tasks. Learn more about this process here.
AnyView’s impact on SwiftUI performance
Using the AnyView structure can significantly hinder your app's performance. Tests on real devices indicated frame rate drops of up to 10% when scrolling tables and up to 16% during frequent data updates. Exercise caution with AnyView.
Learn how to identify such performance issues using the Instruments app here.