UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Learn SwiftUI with SwiftUI By Example

Article Many people are keen to learn SwiftUI in the fastest way possible, which is why I wrote SwiftUI By Example: a comprehensive, free collection of example code that helps you get started with SwiftUI today. Not only does SwiftUI By E... Read more >>

Learn SwiftUI with free tutorials

Article SwiftUI was announced during the keynote at WWDC19, and already there are a huge number of free tutorials as articles, YouTube videos, books, and more – it’s safe to say that folks are really exc... Read more >>

Xcode 12 wish list: SwiftUI, iPadOS, and more

Article ...e community what they most wanted to see. Unsurprisingly I was inundated with responses – as much as we love working with Xcode, there are always things it can do better. Let’s dive in… SwiftUI or bust WWDC19 came with lots of massive announcements from Apple, but almost all of them were swept away by the behemoth that is SwiftUI. Although it’s still very early in SwiftUI’s publi... Read more >>

How to build your first SwiftUI app with Swift Playgrounds

Article Swift Playgrounds lets you build a complete iOS app from scratch, right on your iPad. You get to draw upon Apple’s powerful SwiftUI framework, you can pull in libraries that other people have written, and if you want you can even move your project over to your Mac and continue it in Xcode, Apple’s full-blown code editor.... Read more >>

Build your first app with SwiftUI and SwiftData

Article In this article we're going to build a complete iOS app using SwiftUI and SwiftData, all while building a real app so you can see all the techniques in action. The app we're building is called FaceFacts, which is designed to help you remember the names, faces, a... Read more >>

Answering the big question: should you learn SwiftUI, UIKit, or both?

Example Code Of all the SwiftUI questions I’ve been asked, one comes up more than any other: “I’m learning Swift: should I learn SwiftUI or do I need to learn UIKit as well?” The answer folks seem to want to hear is ... Read more >>

Get started with SwiftUI

Article SwiftUI is Apple's incredible new user interface framework for building apps for iOS, macOS, tvOS, and even watchOS, and brings with it a new, declarative way of building apps that makes it faster and... Read more >>

Frequently asked questions about SwiftUI

Example Code Lots of people are already asking me questions about SwiftUI, and I’ve done my best to ask other people who know much more to try to find definitive answers as appropriate. So, here goes… Which to learn: SwiftUI or UIKit? This question has been aske... Read more >>

The Complete Guide to NavigationView in SwiftUI

Article NavigationView is one of the most important components of a SwiftUI app, allowing us to push and pop screens with ease, presenting information in a clear, hierarchical way for users. In this article I want to demonstrate the full range of ways you can use Navi... Read more >>

5 Steps to Better SwiftUI Views

Article As SwiftUI projects grow more complex, it’s common to find your views get larger and larger as you cram more functionality into them. In this article I’ll walk you through the underlying problem, and... Read more >>

8 Common SwiftUI Mistakes - and how to fix them

Article SwiftUI is a big and complex framework, and although it’s great fun to work with there’s also a lot of scope for making mistakes. In this article I’m going to walk through eight common mistakes ... Read more >>

The Complete Guide to Layout in SwiftUI

Article SwiftUI gives us a huge range of tools to control layouts, from the core tools of HStack, VStack, and ZStack, through to more advanced views such as GeometryReader and Group, plus modifiers such as la... Read more >>

Special Effects with SwiftUI

Article Everyone knows SwiftUI does a great job of creating standard system layouts with lists, buttons, navigation views, and more, and while it’s really useful I doubt most people would call it fun. So, in this article ... Read more >>

SwiftUI tips and tricks

Example Code SwiftUI is packed with powerful headline features, but there are also dozens of smaller tips and tricks that will help you write better apps. I’ve tried to summarize all the tips I’ve come across ... Read more >>

How to build neumorphic designs with SwiftUI

Article ...esign trend of recent months, although to be fair Apple did use it as their design motif way back in WWDC18. In this article we’re going to look at how you can build neumorphic designs using SwiftUI, why you might want to, and – most importantly – how we can modify those designs to be more accessible. Important: Neumorphism – sometimes called neomorphism – has serious implication... Read more >>

Integrating Core Image with SwiftUI

Project ...ou ever used all the various photo effects available in Apple’s Photo Booth app, that should give you a good idea of what Core Image is good for! However, Core Image doesn’t integrate into SwiftUI very well. In fact, I wouldn’t even say it integrates into Apple's older UIKit framework very well – they did some work to provide helpers, but it still takes quite a bit of thinking. Sti... Read more >>

SwiftUI lets us build declarative user interfaces in Swift

Article ... can be messy to use with source control, they make it hard if not impossible to move between code and visual layouts, and they rely on a flaky system of connections using actions and outlets. SwiftUI sweeps all that away in several important ways: There’s a new declarative UI structure that defines how our layouts look and work. Updating the UI preview automatically generates new Swift ... Read more >>

Using coordinators to manage SwiftUI view controllers

Project Previously we looked at how we can use UIViewControllerRepresentable to wrap a UIKit view controller so that it can be used inside SwiftUI, in particular focusing on PHPickerViewController. However, we hit a problem: although we could show the image picker, we weren’t able to respond to the user selecting an image or pressing c... Read more >>

How to use Instruments to profile your SwiftUI code and identify slow layouts

Example Code Xcode’s Instruments tool comes with a fantastic set of analytics for SwiftUI, allowing us to identify how often views were redrawn, how many times calculating the body of a view was slow, and even how our state has changed over time. First, we need something that is ab... Read more >>

How to add Metal shaders to SwiftUI views using layer effects

Example Code New in iOS 17 SwiftUI provides extensive integration with Metal shaders, right at the very view level – we can manipulate colors, shapes, and more with remarkable performance. Trying this out takes three steps: ... Read more >>

Start the 100 Days of SwiftUI!

Article If you're looking for free SwiftUI tutorials, I have just the thing for you: the 100 Days of SwiftUI is an all-new online course teaching you how to build a variety of real-world apps with SwiftUI. The course starts with the sa... Read more >>

How to fix slow List updates in SwiftUI

Article If you have a SwiftUI list with lots of rows, you might find it's really slow to update when you sort or filter those rows – code that should run instantly might take one or two seconds, or if you have lots of i... Read more >>

How to combine Core Data and SwiftUI

Project SwiftUI and Core Data were introduced almost exactly a decade apart – SwiftUI with iOS 13, and Core Data with iPhoneOS 3; so long ago it wasn’t even called iOS because the iPad wasn’t released ... Read more >>

How to use inner shadows to simulate depth with SwiftUI and Core Motion

Article SwiftUI comes with a whole range of advanced effects we can use to customize the way our content is drawn, and from iOS 16 onwards we gain another important option: the ability to create inner shadows... Read more >>

How to use SwiftUI in Swift Playgrounds

Article Apple just updated its Swift Playgrounds iPad app with support for Swift 5.1, dark mode, and SwiftUI, which means it’s now possible to try building SwiftUI apps and components entirely on your iPad. Although Swift Playgrounds comes with a handful of templates for various kinds of projects, ... Read more >>

Wrapping a UIViewController in a SwiftUI view

Project SwiftUI is a really fantastic framework for building apps, but right now it’s far from complete – there are many things it just can’t do, so you need to learn to talk to UIKit if you want to add... Read more >>

What’s new in SwiftUI for iOS 15

Article Expectations were always going to be high for SwiftUI this year, but the team didn’t disappoint – they’ve shipped a massive collection of improvements and features, including a new AsyncImage view for loading remote images, swipe actions f... Read more >>

How layout works in SwiftUI

Project All SwiftUI layout happens in three simple steps, and understanding these steps is the key to getting great layouts every time. The steps are: A parent view proposes a size for its child. Based on that i... Read more >>

Absolute positioning for SwiftUI views

Project SwiftUI gives us two ways of positioning views: absolute positions using position(), and relative positions using offset(). They might seem similar, but once you understand how SwiftUI places views in... Read more >>

How to become a SwiftUI expert

Example Code Everything in this guide is designed to help you solve hands-on, practical problems with your SwiftUI code, and it focuses specifically on helping you write SwiftUI projects effectively. But if you want to really extend your skills – if you want to understand how SwiftUI works behind the sce... Read more >>

Why does SwiftUI use “some View” for its view type?

Project SwiftUI relies very heavily on a Swift power feature called “opaque return types”, which you can see in action every time you write some View. This means “one object that conforms to the View pr... Read more >>

Sharing SwiftUI state with @Observable

Project If you use @State with a struct, your SwiftUI view will update automatically when a value changes, but if you use @State with a class then you must mark that class with @Observable if you want SwiftUI to watch its contents for changes. To... Read more >>

Working with Identifiable items in SwiftUI

Project When we create static views in SwiftUI – when we hard-code a VStack, then a TextField, then a Button, and so on – SwiftUI can see exactly which views we have, and is able to control them, animate them, and more. But when we us... Read more >>

Introduction to SwiftData and SwiftUI

Project SwiftUI is a powerful, modern framework for building great apps on all of Apple's platforms, and SwiftData is a powerful, modern framework for storing, querying, and filtering data. Wouldn't it be nic... Read more >>

What’s the difference between Swift and SwiftUI?

Article When you’re just learning Swift and SwiftUI the first time, you might look at Swift and SwiftUI and imagine that they are two competing choices for you to pick from. So, it’s perfectly understandable to ask what’s the difference bet... Read more >>

How to render a SwiftUI view to a PDF

Example Code New in iOS 16 SwiftUI’s ImageRenderer class can render views any SwiftUI views to PDFs, and yes: all the text and shapes remain vectors, so they scale up beautifully. Creating a PDF with ImageRenderer takes eight... Read more >>

What is SwiftUI?

Example Code SwiftUI is a user interface toolkit that lets us design apps in a declarative way. That’s a fancy way of saying that we tell SwiftUI how we want our user interface to look and work, and it figures o... Read more >>

SwiftUI vs Interface Builder and storyboards

Example Code ...e them, but they are at least familiar with them. If you haven’t used these before, you should just skip this bit. Still here? That means you’ve used IB before and are probably curious how SwiftUI is different. Well, let me ask you this: have you ever edited a storyboard or XIB by hand? Probably not. Well, apart from that one time once, but broadly the answer is no – storyboards and X... Read more >>

What’s new in SwiftUI for iOS 17

Article SwiftUI continues to evolve at a rapid pace, and this year has seen a huge number of improvements to scroll views, fun new SF Symbols effects, advanced support for Metal shaders, and more. Some of the... Read more >>

How to delete Core Data objects from SwiftUI views

Example Code Deleting Core Data objects in SwiftUI is mostly the same as deleting them in UIKit, although there are a couple of special hoops to jump through to integrate with SwiftUI’s views. If you followed my Core Data and SwiftUI set up ... Read more >>

Why does SwiftUI use structs for views?

Project If you ever programmed for UIKit or AppKit (Apple’s original user interface frameworks for iOS and macOS) you’ll know that they use classes for views rather than structs. SwiftUI does not: we prefer to use structs for views across the board, and there are a couple of reasons why. First, there is an element of performance: structs are simpler and faster than classes. I ... Read more >>

Two-way bindings in SwiftUI

Example Code If you look in the SwiftUI preview window you’ll see the standard iOS picker interface – a pop up menu of options. By default it will show the first option, because it reads the value of paymentType, which we set to... Read more >>

How to convert a SwiftUI view to an image

Example Code Improved in iOS 16 SwiftUI’s ImageRenderer class is able to render any SwiftUI view hierarchy into an image, which can then be saved, shared, or reused somehow else. At its simplest, the code needed is this: let rende... Read more >>

Understanding the basic structure of a SwiftUI app

Project When you create a new SwiftUI app, you’ll get a selection of files and maybe 20 lines of code in total. Inside Xcode you should see the following files in the space on the left, which is called the project navigator: We... Read more >>

One-to-many relationships with Core Data, SwiftUI, and @FetchRequest

Project ..., this is one area where Core Data shows its age a little: to get relationships to work well we need to make a custom NSManagedObject subclass that providers wrappers that are more friendly to SwiftUI. To demonstrate this, we’re going to build two Core Data entities: one to track candy bars, and one to track countries where those bars come from. Relationships come in four forms: A one ... Read more >>

Paths vs shapes in SwiftUI

Project SwiftUI enables custom drawing with two subtly different types: paths and shapes. A path is a series of drawing instructions such as “start here, draw a line to here, then add a circle there”, all... Read more >>

What’s new in SwiftUI for iOS 16

Article ... and once again was absolutely packed with new features for app developers – huge new features in Swift 5.7, new APIs such as WeatherKit and Swift Charts, and, of course, lots of goodies for SwiftUI developers. Please keep in mind that these changes are very new – I'm pushing it as hard as I can, experimenting, refining, sharing, and learning all at the same time. If you have any feedba... Read more >>

All SwiftUI property wrappers explained and compared

Example Code SwiftUI offers 17 property wrappers for our applications, each of which provide different functionality. Knowing which one to use and when is critical to getting things right, so in this article I’m... Read more >>

How to run tasks using SwiftUI’s task() modifier

Example Code SwiftUI provides a task() modifier that starts a new detached task as soon as a view appears, and automatically cancels the task when the view disappears. This is sort of the equivalent of starting a ... Read more >>

Creating custom paths with SwiftUI

Project SwiftUI gives us a dedicated Path type for drawing custom shapes. It’s very low level, by which I mean you will usually want to wrap it in something else in order for it to be more useful, but as it... Read more >>

How to support drag and drop in SwiftUI

Example Code Improved in iOS 16 SwiftUI’s Transferable protocol allows us to add drag and drop support to our apps without a great deal of code, using the dropDestination() and draggable() modifiers. For example, this will accept ... Read more >>

Integrating MapKit with SwiftUI

Project ...n a core feature of iPhone since the very first device shipped way back in 2007, and the underlying framework has been available to developers for almost as long. Even better, Apple provides a SwiftUI Map view that wraps up the underlying map framework beautifully, letting us place maps, annotations, and more alongside the rest of our SwiftUI view hierarchy. Let’s start with something sim... Read more >>

How to add Core Data objects from SwiftUI views

Example Code Saving Core Data objects in SwiftUI works in exactly the same way it works outside of SwiftUI: get access to the managed object context, create an instance of your type inside that context, then save the context when you’re re... Read more >>

Introduction to using Core Data with SwiftUI

Example Code As two massive pieces of Apple’s software platform, it won’t surprise you to learn that Core Data and SwiftUI have been written to work well together: we get property wrappers, environment support, and more, all to make sure we can integrate Core Data into our SwiftUI apps with the least hassle. Befor... Read more >>

What is behind the main SwiftUI view?

Project When you’re just starting out with SwiftUI, you get this code: struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foreground... Read more >>

Wrap up: our SwiftUI project is complete

Example Code I’m not going to claim this was an easy project, particularly because SwiftUI forces us to think in such a different way from UIKit. Not only do we have the declarative, reactive approach to logic, but we also have @State, environment objects, two-way bindings, and more... Read more >>

SwiftUI tutorial: Building a complete project

Example Code This is a complete, free SwiftUI tutorial designed to take you through lots of its functionality in a single project. It’s aimed at people who have existing programming experience with UIKit, but most things are explained i... Read more >>

Connecting SwiftUI to Core ML

Project In the same way that SwiftUI makes user interface development easy, Core ML makes machine learning easy. How easy? Well, once you have a trained model you can get predictions in just two lines of code – you just need to... Read more >>

Dynamically filtering @FetchRequest with SwiftUI

Project One of the SwiftUI questions I’ve been asked more than any other is this: how can I dynamically change a Core Data @FetchRequest to use a different predicate or sort order? The question arises because fetch re... Read more >>

What’s new in SwiftUI for iOS 14

Article SwiftUI was inevitably going to see big changes this year, and I’m really excited to experiment with them all – text views, color pickers, progress views, and even limited support for grids have ... Read more >>

SwiftUI by Example: Now updated for iOS 16

Article This week I published the biggest ever update to SwiftUI by Example, adding lots of new sample code plus 100 new Xcode projects to download. The initial goal was to update the book for iOS 16, but I ended up going back and adding coverage of functio... Read more >>

Working with two side by side views in SwiftUI

Project ...or a list of Apollo missions, and a secondary view to act as further information, such as more details about a book or Apollo mission selected in the primary view. In our trivial code example, SwiftUI interprets the single view inside our NavigationView as being the primary view in this primary/secondary layout. However, if we do provide two views then we get some really useful behavior out... Read more >>

Introducing Inferno: Metal shaders for SwiftUI

Article SwiftUI for iOS 17 and macOS Sonoma come with a fantastic new superpower: the ability to transform any SwiftUI view with Metal shaders, all hardware accelerated so complex effects run at lightning fas... Read more >>

How to use gestures in SwiftUI

Project SwiftUI gives us lots of gestures for working with views, and does a great job of taking away most of the hard work so we can focus on the parts that matter. Easily the most common is our friend onTap... Read more >>

Controlling image interpolation in SwiftUI

Project What happens if you make a SwiftUI Image view that stretches its content to be larger than its original size? By default, we get image interpolation, which is where iOS blends the pixels so smoothly you might not even realize t... Read more >>

Scanning QR codes with SwiftUI

Project Scanning a QR code – or indeed any kind of visible code such as barcodes – can be done by Apple’s AVFoundation library. This doesn’t integrate into SwiftUI terribly smoothly, so to skip over a whole lot of pain I’ve packaged up a QR code reader into a Swift package that we can add and use directly inside Xcode. My package is called CodeScanner,... Read more >>

Dynamically sorting and filtering @Query with SwiftUI

Project ...arate view – a view specifically for running the SwiftData query and showing its results, then make it optionally show all users or only users who are joining in the future. So, create a new SwiftUI view call UsersView, give it a SwiftData import, then move the List code there without moving any of its modifier – just the code shown above. Now that we're displaying SwiftData results in... Read more >>

Understanding property wrappers in Swift and SwiftUI

Example Code SwiftUI relies heavily on property wrappers to make our code easier to read, write, and maintain, but if you’ve never used them before you might wonder where all the @ and $ signs have come from –... Read more >>

How to make SwiftUI modifiers safer to use with @warn_unqualified_access

Example Code Every SwiftUI makes the same mistake at some point, and sadly it’s something you’ll do more than once: rather than writing .someModifier() you write someModifier(), and it causes your app to completely ... Read more >>

Sending and receiving Codable data with URLSession and SwiftUI

Project ...ert Swift objects to JSON for sending, then receive back JSON to be converted back to Swift objects. Even better, when the request completes we can immediately assign its data to properties in SwiftUI views, causing our user interface to update. To demonstrate this we can load some example music JSON data from Apple’s iTunes API, and show it all in a SwiftUI List. Apple’s data includes ... Read more >>

Introduction to accessibility with SwiftUI

Example Code By default SwiftUI apps come with a remarkably high level of accessibility, which is no accident – it was planned into the framework from the earliest days, and unless you actively choose to work around the de... Read more >>

How to configure Core Data to work with SwiftUI

Example Code If you create a new project and check both SwiftUI and Core Data, Xcode does a pretty good job of getting you towards a working configuration. Specifically, it: Creates an empty YourProjectName.xcdatamodeld model file with an example configur... Read more >>

How to use UIBezierPath and CGPath in SwiftUI

Example Code If you have existing paths made using UIBezierPath or CGPath it’s trivial to convert them for use in SwiftUI because the Path struct has an initializer directly from CGPath. Note: UIBezierPath is not available in macOS, so if you’re trying to keep your SwiftUI code cross platform you should migrate... Read more >>

Migrating from UIKit to SwiftUI

Example Code If you’ve used UIKit before, many of the classes you know and love map pretty much directly to their SwiftUI equivalents just by dropping the UI prefix. That doesn’t mean they are the same thing underneath, just that they have the same or similar functionality. Here’s a list to get you started, w... Read more >>

Important: Do not use an actor for your SwiftUI data models

Example Code ... data. Actors are an important addition to our toolset, and help us guarantee safe access to data in concurrent environments. However, if you’ve ever wondered “should I use an actor for my SwiftUI data?”, let me answer that as clearly as I can: actors are a really bad choice for any data models you use with SwiftUI – anything that conforms to the ObservableObject protocol. SwiftUI ... Read more >>

Supporting specific accessibility needs with SwiftUI

Project SwiftUI gives us a number of environment properties that describe the user’s custom accessibility settings, and it’s worth taking the time to read and respect those settings. Back in project 15 we... Read more >>

How to add an AppDelegate to a SwiftUI app

Example Code SwiftUI apps launch using a custom struct that conforms to the App protocol, but sometimes you might want to get back the old UIApplicationDelegate functionality we used to have – perhaps to handle... Read more >>

How to continue an NSUserActivity in SwiftUI

Example Code SwiftUI has a dedicated onContinueUserActivity() modifier that can catch a variety of NSUserActivity types – clicks from the web, launches from Spotlight or Siri, and more. Previously you might hav... Read more >>

How to wrap a custom UIView for SwiftUI

Example Code Although SwiftUI does a good job of providing many of UIKit’s UIView subclasses, it doesn’t have them all yet at this time. Fortunately, it’s not hard to create custom wrappers for a UIView that you want... Read more >>

Importing an image into SwiftUI using PHPickerViewController

Project ...ady have most of the code you need. If you missed those chapters, it’s not too late: create a new Swift file called ImagePicker.swift, then replace its code with this: import PhotosUI import SwiftUI struct ImagePicker: UIViewControllerRepresentable { @Binding var image: UIImage? func makeUIViewController(context: Context) -> PHPickerViewController { var config = PHPicker... Read more >>

Special effects in SwiftUI: blurs, blending, and more

Project SwiftUI gives us extraordinary control over how views are rendered, including the ability to apply real-time blurs, blend modes, saturation adjustment, and more. Blend modes allow us to control the w... Read more >>

Creating a spirograph with SwiftUI

Project To finish off with something that really goes to town with drawing, I’m going to walk you through creating a simple spirograph with SwiftUI. “Spirograph” is the trademarked name for a toy where you place a pencil inside a circle and spin it around the circumference of another circle, creating various geometric patterns that ar... Read more >>

Introducing MVVM into your SwiftUI project

Project So far I’ve introduced you to a range of concepts across Swift and SwiftUI, and I’ve also dropped a few tips on ways to organize your code better. Well, here I want to explore that latter part a bit further: we’re going to look at what is commonly called a softwa... Read more >>

Common SwiftUI errors and how to fix them

Example Code As great as SwiftUI is, it’s fair to say that its error messages can sometimes be a little unhelpful. Often you’ll get an error on line 5 when really the error is on line 10, and its common for the messages y... Read more >>

Using Touch ID and Face ID with SwiftUI

Project ...to us too, which means we can make sure that sensitive data can only be read when unlocked by a valid user. This is another Objective-C API, but it’s only a little bit unpleasant to use with SwiftUI, which is better than we’ve had with some other frameworks we’ve looked at so far. Before we write any code, you need to add a new key to your project options, explaining to the user why y... Read more >>

Importing an image into SwiftUI using PhotosPicker

Project ...life, we need to let the user select a photo from their library, then display it in ContentView. This takes a little thinking, mostly because of the roundabout way Core Image works compared to SwiftUI. First we need to add an import for PhotosUI to the top of ContentView, then give it an extra @State property to track whatever picture the user selected: @State private var selectedItem: Phot... Read more >>

How to access a Core Data managed object context from a SwiftUI view

Example Code If you followed my Core Data and SwiftUI set up instructions, you’ve already injected your managed object context into the SwiftUI environment. If not, make sure you add this code to your scene delegate: ContentView() .environm... Read more >>

Customizing animations in SwiftUI

Project When we attach the animation() modifier to a view, SwiftUI will automatically animate any changes that happen to that view using whatever is the default system animation, whenever the value we’re watching changes. In practice, that is a very gentle ... Read more >>

SwiftUI’s built-in shapes

Example Code Improved in iOS 17 SwiftUI gives us five built-in shapes that are commonly used: rectangle, rounded rectangle, circle, ellipse, and capsule. The last three in particular are subtly different in how they behave based on ... Read more >>

How to add in-app purchases in SwiftUI

Example Code ... Text("Sign in here") } .subscriptionStoreControlStyle(.prominentPicker) } } Tip: Both privacy and terms of service can be provided as URLs rather than custom SwiftUI views. There are also various options for controlling how the screen looks, all carefully picked out by Apple to ensure all the core functionality remains – that your screen ultimately shows... Read more >>

How to use programmatic navigation in SwiftUI

Example Code Updated for iOS 16 We can use SwiftUI to programmatically push a new view onto a NavigationStack using NavigationLink, meaning that we can trigger the navigation when we’re ready rather than just when the user tapped a button or... Read more >>

Making a SwiftUI view searchable

Project ...xample, you should see a search bar you can type into, and whatever you type will be shown in the view below. In practice, searchable() is best used with some kind of data filtering. Remember, SwiftUI will reinvoke your body property when an @State property changes, so you could use a computed property to handle the actual filtering: struct ContentView: View { @State private var searchT... Read more >>

How to be notified when your SwiftUI app moves to the background

Project SwiftUI can detect when your app moves to the background (i.e., when the user returns to the home screen), and when it comes back to the foreground, and if you put those two together it allows us to m... Read more >>

Handling voice input in SwiftUI

Project ...ed") } That will work great as "Tap John Fitzgerald Kennedy", but wouldn't it be great to also recognize "Tap Kennedy" or perhaps even "Tap JFK"? How about recognizing all three? This is where SwiftUI needs a little extra help from us using the accessibilityInputLabels() modifier. This accepts an array of strings that can be attached to our button, so the user can trigger it in a variety of... Read more >>

Relationships with SwiftData, SwiftUI, and @Query

Project ...tical, 5) .background(.blue) .foregroundStyle(.white) .clipShape(.capsule) } } If you want to see it work with some actual data, you can either create a SwiftUI view to create new Job instances for the selected user, but for testing purposes we can take a little shortcut and add some sample data. First add a property to access the active SwiftData mod... Read more >>

How to find which data change is causing a SwiftUI view to update

Example Code SwiftUI provides a special, debug-only method call we can use to identify what change caused a view to reload itself. The method is specifically for debugging, and should not be shipped in a real app,... Read more >>

Formatting interpolated strings in SwiftUI

Example Code ...totalPrice: String { let total = Double(order.total) let tipValue = total / 100 * Double(tipAmount) return (total + tipValue).formatted(.currency(code: "USD")) } Now, remember that SwiftUI will re-invoke our body property whenever any of our @State properties change. As a result, we can use that computed property right inside our layout, and it will automatically change as the s... Read more >>

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.