We’ve arrived at day 81 of the 100 Days of SwiftUI. Yesterday, we learned about Swift’s
Result type, as well as image interpolation and manually publishing changes to properties. Today, we’ll focus on adding context menus, custom swipe actions and more. Let’s dive in!
Creating context menus in SwiftUI
When our users interact with buttons in our app, it’s clear what will happen when they press a button if we label it clearly. However, what if a user presses and holds a button? Normally, nothing would happen. However, we can add a context menu with even more options that our users can choose from, which will show when a user long presses on a button. This is done by using SwiftUI’s
Adding custom row swipe actions to a List
Our lists have had an option to swipe to delete items in our rows. However, what if we want custom actions? For example, when using a mail app you might want to swipe to mark an email as read or archive it. By adding a
swipeActions() modifier in SwiftUI, we can modify the actions our users can pick from when swiping on an item in our row.
Scheduling local notifications
iOS has a framework called UserNotifications that does pretty much exactly what you expect: lets us create notifications to the user that can be shown on the lock screen. We have two types of notifications to work with, and they differ depending on where they were created: local notifications are ones we schedule locally, and remote notifications (commonly called push notifications) are sent from a server somewhere.Hacking with Swift, Paul Hudson (@twostraws)
And that’s it for day 81! We’ve learned a lot of great techniques to improve our apps, notifications being a big one in my opinion. We’ll continue with this project the coming days, so stay tuned. For now though, it’s time to recharge!