Share your work and get the
Latest iOS dev beans

Stay up to date with articles, tips and apps submitted by the dev community delivered directly to your inbox. Swift, iOS, macOS, watchOS, SwiftUI, UIKit and more.
Curated by Tiago Henriques and published every week.

No spam, ever. Unsubscribe at any time.
By subscribing you consent to processing of your data
as described in the privacy policy.

Issue #29

January 20, 2025

✅ Part 2 of Bringing App Intents to Your SwiftUI App 🍭

Sponsored

Tuist - Scale your Swift App development

We are an integrated and open core toolchain that extends Apple's official tools with insights, optimizations, and workflows to help you build better apps faster.

Welcome to issue #29 of the iOS Coffee Break Newsletter 📬 and the second edition of 2025.

Last week issue discussed the advantages and implementation details of the App Intents and the App Shortcuts frameworks in iOS, using a to-dos sample application as a working example.

In case you missed the previous issue, you can check it out here.

Do you recall the boring dialog that gets displayed when our todo is marked as completed? What if there is a way to improve it 🤔 ...

This week, I will show how you can take App Intents to the next level by taking advantage of the ShowsSnippetView protocol to return a custom view as a result of performing an action.

Jumping to the Code

First, lets create our view. Here is how the custom TodoActionView looks:

import SwiftUI
 
struct TodoActionView: View {
    let action: TodoAction
    let title: String
 
    var body: some View {
        HStack {
            Image(systemName: action.imageName)
                .imageScale(.large)
                .font(.largeTitle)
            Text("'\(title)' \(action.name).")
                .font(.title2)
        }
        .padding()
    }
}

To display a view when marking a to-do as completed, update the perform method's return type to include ShowsSnippetView. Then, use the result method to pass TodoActionView as a parameter.

Here is how the code looks:

import AppIntents
import SwiftUI
 
struct MarkTodoAsCompletedIntent: AppIntent {
    [...]
 
    func perform() async throws -> some ShowsSnippetView {
        let suggestedEntities = try await suggestedEntities()
        if suggestedEntities.isEmpty {
            return await .result(view: TodosEmptyView())
        } else {
            let entityToUpdate = try await $titleEntity.requestDisambiguation(
                among: suggestedEntities,
                dialog: IntentDialog("Select the todo you wish to mark as completed:")
            )
            // mark todo as completed
            try await markAsCompleted(title: entityToUpdate.id)
            return .result(view: TodoActionView(action: .markAsComplete, title: entityToUpdate.id))
        }
    }
 
    [...]
}

With that simple adjustment, the App Intent action delivers a custom and more engaging view. Here is how the demo of the sample to-dos application now behaves:

For those interested in diving deeper into this topic, consider experimenting with various types of intents to see how they can be customized to meet your app's specific needs.

If you are considering adding App Intents to your app, make sure to review the Human Interface Guidelines. They provide valuable insights into what types of actions are suitable for App Intents, ensuring they align with best practices and offer an intuitive user experience.

I am planning to release a 3rd part of my App Intents issues by powering up my to-do sample application with interactive widgets! Stay tunned!

To explore the full implementation of the sample application, visit the to-dos app repository on GitHub.

Now it is time to dive into some iOS development topics submitted by the community. Here are this week's highlighted resources. Hope you enjoy 🙌.

CURATED FROM THE COMMUNITY

🤘 Favorite Xcode shortcuts

Xcode offers countless shortcuts, and I am sure everyone has their go-to favorites. In his latest article, Nowham highlights the most useful shortcuts he relies on daily. It is a must-read for improving efficiency!

If you are like me and keep mistyping variables names all the time, the Edit all in scope shortcut comes pretty handy!

🔨 Swift Argument Parser with Guilherme Rambo

Swift Toolkit has released an insightful video featuring Natan and Gui Rambo, where they delve into Command Line tools in Swift. They showcase a practical refactor and demonstrate integrating CLI functionality into macOS apps.

If you are passionate about tooling and server side in Swift, Swift Toolkit is the right place for you.

🧑‍💻 Attending Apple Intelligence and App Intents workshop

While researching for my latest issue, I came across Dean's blog and his insightful article on Apple Intents. Dean recently attended an Apple Intelligence and App Intents workshop in Paris, led by an Apple expert, and shared his experience in detail.

It is exciting to see Apple hosting such local events worldwide. I would be thrilled to have the chance to participate in one someday!

✂️ Introduction to Non-Copyable types in Swift

Have you come across non-copyable types in Swift? I hadn't until recently!

This new feature, recently introduced to Swift, enhances code safety by preventing unintended copying of certain types. If you are curious to learn more, Vincent has created a straightforward video explaining the concept and its practical applications.