10 Code Snippets from WWDC20

Francesco Marisaldi
The Startup
Published in
4 min readJul 2, 2020

➡️ UPDATE: read 8 Tidbits from WWDC23 ⬅️

The week of online WWDC 2020 has unveiled big features and exciting announcements; among with important news, there’re many other notable additions coming with new SDKs. Here’s a list of 10 code snippets will be available with the next iOS’s major release: no more than 5 lines of code each. Let’s start 🧑🏼‍💻

1. SKOverlay

The first api enables us to display an overlay to recommend another app, allowing the user to download it immediately. You can configure the position and set a delegate, in order to respond to events such as appearance, dismissal and errors.

It differs from SKStoreProductViewController because it’s tailored for apps and it’s an overlay rather than a full view. Using the dedicated configuration for clips, the SKOverlay.AppClipConfiguration, you’re able to recommend the app clip’s corresponding app, as showed in demos about App Clips.

2. Configurations

Configurations is a brand new api to specify content and appearance of views and cells. It’s very flexible, because it can be applied to any UIView, including collection and table view cells, and very simple to use at the same time. This is an example of using UIListContentConfiguration:

List content configuration comes with many default configurations. Configurations covers state, content and background specifications; in addition, it’s replacing deprecated tableview cell’s textLabel, detailTextLabel and imageView attributes. Dive into the documentation to learn about all features and use cases.

3. Lists in Collection View

Starting from iOS 14, collection views can now be configured with a list layout, which has a UITableView like appearance (someone marked this as the end of table view’s era), the simple setup is:

Lists come with different styles and list cells with swipe gestures, separators, accessories: Lists in UICollectionView session covers much of these details.

4. Location accuracy

There’re many news about Core Location, included the new accuracy permission, which allows users to choose between full and reduced accuracy when they share their location with apps. What if you need the precise location for a particular feature of your app and the user shared only the approximate one? You’re able to ask for it by using:

The temporary accuracy lasts for the running session only; the key must be added in the NSLocationTemporaryUsageDescriptionDictionary inside the app’s Info.plist and you can add as much keys as you need, to cover different use cases. If you’re interested, I suggest to watch What’s new in location and Design for location privacy sessions from WWDC20.

5. Tracking authorization (2021)

This year focus on user’s privacy didn't cover only location and web browsing, but also data used by apps. If you access the user’s IDFA and other sensible data for tracking purpose, you’re now required to ask permission to users using the new AppTrackingTrasparency framework:

You also need to specify the NSUserTrackingUsageDescription key in the Info.plist. Users can even opt-out entirely from this request, meaning that alerts from any apps will not be fired: the Build trust through better privacy session shows more about this topic.

6. Init UIControls with an action parameter

UIControls can now be instantiated with a handy primary action as parameter using a closure (no more selectors 🎉), like:

Same for UIBarButtonItem or UISegmentedControl (with an array of actions in this case); segmented controls get some other useful methods, like the ability to insert a segment with an action at a specified index.

7. Menu from buttons

Menus can now be shown from any buttons and the Human Interface Guidelines encourages this for many use cases: a good example is the “history menu” showed with a long tap on the back button in a navigation bar. Showing a UIMenu from a button is really easy thanks to the new initializer:

8. UIColorPickerViewController

Yes, an easy to use controller to manage the selection of a color from a UIColorWell 🎨 using colorPickerViewControllerDidFinish(_:) and colorPickerViewControllerDidSelectColor(_:) delegate’s methods:

9. UIPageControl and UIDatePicker additions

UIPageControl has new nice features, included the ability to set images as custom page indicators. UIDatePicker comes with a brand new UI, a pop-up menu and the new .inline style:

10. Mac Idiom

Thanks to the new mac user interface idiom, it’s now more convenient to optimize UIs and behaviors for Catalyst apps (well, not only Catalyst apps, as any apps will potentially be able to run on Macs powered by Apple Silicon):

if UIDevice.current.userInterfaceIdiom == .mac { //Your code }

And that's all! Hope you enjoyed Dub-Dub as me, we have big features and small improvements to dive in during next months. Feel free to connect with me on Twitter and Mastodon; thanks for reading and catch up on the next article ☕️

--

--