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

That page doesn't exist, but based on searching the site here are some pages that might be what you're looking for…

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 Example walk you through well over 100 commo... Read more >>

Learn SwiftUI with free tutorials

Article ...re keen to share that excitement with the world. I’ve created a wide range of SwiftUI tutorials myself, but I’ve also been reading tutorials from many other developers. In this article I’ve brought together tutorials from a variety of folks, because everyone learns differently – hopefully you’ll find a tutorial that teaches SwiftUI in a way that works great for you... Read more >>

Xcode 12 wish list: SwiftUI, iPadOS, and more

Article Xcode 11 is about to ship as gold master, which means Apple’s teams are already hard at work on future features. Although it’s always nice to have surprise new functionality, it’s also smart to let Apple... Read more >>

How to build your first SwiftUI app with Swift Playgrounds

Article ...ull 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. In this tutorial I’m going to walk you through building your very first app using Swift Playgrounds for iPad, where you’ll be able to show pictures of your friends and family, and tapping one of them w... 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, w... Read more >>

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

Example Code ...’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 “forget that old UIKit thing – you should focus on SwiftUI!” However, the simple truth is that the vast majority of people won’t find success with that advice, and it’s worth explaining ... 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 safer t... Read more >>

Frequently asked questions about SwiftUI

Example Code ...ut 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 asked so many times I added a dedicated chapter to this book so I could go into more detail: answering the big question: should you learn SwiftUI, UIKit, or both? Where can SwiftU... 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 demons... 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 demonstrate five steps you can take to make your views simpler, smaller, and smarter – all demonstrated using a real SwiftUI project, s... 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 SwiftUI ... Read more >>

The Complete Guide to Layout in SwiftUI

Article ... layouts, from the core tools of HStack, VStack, and ZStack, through to more advanced views such as GeometryReader and Group, plus modifiers such as layoutPriority(). I’ve published a lot of articles and videos about those and more, but this article brings them all together in one place for easy reference. If I missed something off this list, let me know on Twitter. How lay... 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 I’m going to show you how to use SwiftUI to build something fun, ... 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 so far b... Read more >>

How to build neumorphic designs with SwiftUI

Article Neumorphic design is easily the most interesting design 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 ... Read more >>

Integrating Core Image with SwiftUI

Project Core Image is Apple's framework for manipulating images. This isn’t drawing, or at least for the most part it isn’t drawing, but instead it’s about changing existing images: applying sharpening, blurs, vig... Read more >>

SwiftUI lets us build declarative user interfaces in Swift

Article Although storyboards and XIBs have served us well, they aren’t to everyone’s liking – they 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 ... Read more >>

Using coordinators to manage SwiftUI view controllers

Project ...er. 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 cancel. SwiftUI’s solution to this is called coordinators, which is a bit confusing for folks coming from a UIKit background because there we had a design pattern also called coordinators that performed an entirely different role. T... Read more >>

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

Example Code ... 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 able to provide interesting results we can look at in Instruments. So, this code creates a timer that triggers every 0.01 seconds, and has a body view that shows a random UUID and a button that inc... 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: Creating a Metal file with your shader. This must have an exact function signature, which varies depending on what kind of effect you’re trying to apply. Creating your Swi... 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 same 15-day Swift fundamentals from the original 100 Days of Swift, but the ... 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 items one ... Read more >>

How to combine Core Data and SwiftUI

Project ...st 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 yet. Despite their distance in time, Apple put in a ton of work to make sure these two powerhouse technologies work beautifully alongside each other, meaning that Core Data integrates into SwiftUI as if it were always de... 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. Inner shadows create the illusion that some shape or text is cut out, placing the shadows on th... Read more >>

How to use SwiftUI in Swift Playgrounds

Article ...wiftUI import PlaygroundSupport struct ContentView: View { var body: some View { Text("Hello World") } } PlaygroundPage.current.setLiveView(ContentView()) At this time support for SwiftUI isn’t ideal: NavigationView doesn’t work well because it tries to run as a split view controller, and there is no support for the instant preview canvas that we get wit... 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 more ad... 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 for list ro... 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 information, the child then chooses its own size and the parent must respect ... Read more >>

Absolute positioning for SwiftUI views

Project ...lar, but once you understand how SwiftUI places views inside frames the underlying differences between position() and offset() become clearer. A simple SwiftUI view looks like this: struct ContentView: View { var body: some View { Text("Hello, world!") } } SwiftUI offers the full available space to ContentView, which in turn passes it on to the text view. The ... 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 ext... 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 protocol, but we don’t want to say what.” Returning some View means even though we don’t know what view type is going back, the compiler does. Th... Read more >>

Sharing SwiftUI state with @Observable

Project ...e @State with a class then you must mark that class with @Observable if you want SwiftUI to watch its contents for changes. To understand what's going on, let's take a look at this code in more detail: @Observable class User { var firstName = "Bilbo" var lastName = "Baggins" } This is a class with two string variables, but it starts with @Observable. That tells SwiftU... 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 use List or ForEach to make dynamic views, SwiftUI needs to know how it can identify each item uniquely otherwise it will struggle to compa... 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 nice if the... Read more >>

What’s the difference between Swift and SwiftUI?

Article ...peting choices for you to pick from. So, it’s perfectly understandable to ask what’s the difference between Swift and SwiftUI, and which should you choose? Well, the reality is a little confusing, at least at first: you need them both. Swift is a programming language, which mean it’s the words we type into our computer to say what our program should do. Swift can be use... Read more >>

How to render a SwiftUI view to a PDF

Example Code ...er. Creating a URL where SwiftUI can write the image data. Calling render() on the image renderer to start your rendering code. Telling SwiftUI how big you want the PDF to be. This might be a fixed size like A4 or US Letter, or might be the size of the view hierarchy you’re rendering. Create a CGContext object to handle the PDF pages. Starting a new page. Rendering the Swif... 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 out how t... Read more >>

SwiftUI vs Interface Builder and storyboards

Example Code Every experienced iOS developer is familiar with Interface Builder and storyboards, and perhaps even XIBs too. They might not like them, but they are at least familiar with them. If you haven’t used these before, you should just s... 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 these are things I’ve asked for personally, includin... 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 instruct... Read more >>

Why does SwiftUI use structs for views?

Project ...w 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 say an element of performance because lots of people think this is the primary reason SwiftUI uses structs, when really it?... Read more >>

Two-way bindings in SwiftUI

Example Code ...ich we set to “Cash”. However, when the user brings up the menu their selection changes – they might select “Credit Card” or “iDine Points” instead of cash. So, this picker doesn’t just read the value of paymentType, it also writes the value. This is what’s called a two-way binding, because any changes to the value of paymentType will update the picker, and... 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 renderer = ImageRenderer(content: Tex... 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: WeSplitApp.swift contains code for launching your app. If you create something when the app launches and keep it alive the entire time, you’ll put it here. ContentV... Read more >>

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

Project Core Data allows us to link entities together using relationships, and when we use @FetchRequest Core Data sends all that data back to us for use. However, 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... 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 using absolute coordinates. In contrast, a shape has no idea where it will be used or ho... Read more >>

What’s new in SwiftUI for iOS 16

Article WWDC was back in person for the first time since 2019, 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, ... 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 going to introduce you to each of them, and give you clear guidance which to use. TL;DR I’m going to explain more in a moment, but here?... 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 task in onAppear() then cancelling it onDisappear(), although task() has an extra ability to track an identifier and restart its task when the i... Read more >>

Creating custom paths with SwiftUI

Project ...ut as it’s the building block that underlies other work we’ll do we’re going to start there. Just like colors, gradients, and shapes, paths are views in their own right. This means we can use them just like text views and images, although as you’ll see it’s a bit clumsy. Let’s start with a simple shape: drawing a triangle. There are a few ways of creating paths, i... Read more >>

How to support drag and drop in SwiftUI

Example Code ...’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 text dragged into our app, and render it onto a Canvas: struct ContentView: View { @State private var message = "" var body: some View { Canvas { context, size in ... Read more >>

Integrating MapKit with SwiftUI

Project ...I view hierarchy. Let’s start with something simple: just showing a map. Maps and all their configuration data come from a dedicated framework called MapKit, so our first step is to import that framework: import MapKit And now we can place a map in our SwiftUI view, with just this: Map() That's enough to show a map on the screen, so try running the app and take a moment to... Read more >>

How to add Core Data objects from SwiftUI views

Example Code ...dObjectContext. In my example setup, we have a ProgrammingLanguage entity with name and creator properties, so we could create one of those inside a SwiftUI button action like this: Button("Insert example language") { let language = ProgrammingLanguage(context: managedObjectContext) language.name = "Python" language.creator = "Guido van Rossum" // more code he... 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 Swift... 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) .foregroundStyle(.tint) ... 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, en... 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... Read more >>

Connecting SwiftUI to Core ML

Project ... should have saved it on your desktop, so please now drag it into the project navigator in Xcode. When Xcode prompts you to “Copy items if needed”, please make sure that box is checked. When you add an .mlmodel file to Xcode, it will automatically create a Swift class of the same name. You can’t see the class, and don’t need to – it’s generated automatically as p... 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 requests are created as a property, so if you try to make ... 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 all landed. Alongside massive improvements to Swif... 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 end... Read more >>

Working with two side by side views in SwiftUI

Project You might not have realized it, but one of the smartest, simplest ways that our apps adapt to varying screen sizes is actually baked right in to NavigationView. You’re already familiar with the basic usage of NavigationView, which allows us to create views like this one: struct ContentView: View { var body: ... Read more >>

Introducing Inferno: Metal shaders for SwiftUI

Article ...plex effects run at lightning fast speeds even on old devices. I want to help folks get started with Metal, so I've produced two free resources that will help everyone: Inferno is an open-source library of Metal shaders written for SwiftUI, giving you a range of powerful special effects in just a few lines of code. I released a new YouTube video where I walk through how to c... 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 onTapGesture(), but there are several others, and there are also interesting ways of combining gestures together that are worth trying out. I’m going to skip past the simple onTapGestu... 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 they have been stretched at all. There’s a performance cost to this of course, but most of the time it’s not worth worrying ab... 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 co... Read more >>

Dynamically sorting and filtering @Query with SwiftUI

Project Now that you've seen a little of how SwiftData's #Predicate works, the next question you're likely to have is "how can I make it work with user input?" The answer is… it's complicated. I'll show you how it's done, and also how the same technique can be used to dynamically adjust sorting, but it's going ... Read more >>

Understanding property wrappers in Swift and SwiftUI

Example Code ...ite alien at first. Although property wrappers are a general Swift feature since they were introduced in Swift 5.1, they are particularly common in SwiftUI – you’ll see @Published, @ObservedObject, @EnvironmentObject and many more, all with the purpose of helping reduce the amount of boilerplate in our code. We’ll be going into detail on each one of SwiftUI’s property... 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 freeze or crash with EXC... Read more >>

Sending and receiving Codable data with URLSession and SwiftUI

Project ... 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 lots of information, but we’re going to whittle it down to just two ... 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 defaults you’ll find your apps do a good job of being accessible withou... Read more >>

How to configure Core Data to work with SwiftUI

Example Code ...ty good job of getting you towards a working configuration. Specifically, it: Creates an empty YourProjectName.xcdatamodeld model file with an example configuration. Adds a Persistence.swift file that wraps up Core Data neatly in one place. Injects the context into the initial content view’s environment using the managedObjectContext key. Provides sample code in ContentVie... 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... Read more >>

Migrating from UIKit to SwiftUI

Example Code ...ir 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, with UIKit class names followed by SwiftUI names: UITableView: List UICollectionView: LazyVGrid and LazyHGrid UIScrollView: ScrollView UILabel: Text UITextField: TextField UIT... Read more >>

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

Example Code ... actor, which means when we make a class conform to ObservableObject we’re agreeing that all our work will happen on the main actor. As an example, any time we modify an @Published property that must happen on the main actor, otherwise we’ll be asking for changes to be made somewhere that isn’t allowed. Now think about what would happen if you tried to use a custom act... Read more >>

Supporting specific accessibility needs with SwiftUI

Project .... Back in project 15 we looked at accessibility labels and hints, traits, groups, and more, but these settings are different because they are provided through the environment. This means SwiftUI automatically monitors them for changes and will reinvoke our body property whenever one of them changes. For example, one of the accessibility options is “Differentiate without col... Read more >>

How to add an AppDelegate to a SwiftUI app

Example Code ...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 registration for push notifications, to respond to memory warnings, to detect time changes, and so on. To do this, first create a custom class that inherits from NSObject and conforms to the UIApplicatio... Read more >>

How to continue an NSUserActivity in SwiftUI

Example Code ...UserActivity() modifier that can catch a variety of NSUserActivity types – clicks from the web, launches from Spotlight or Siri, and more. Previously you might have handled this in your AppDelegate using something like application(_:continue:restorationHandler:), but SwiftUI’s approach is more fine-grained and lets us divide functionality more easily. To implement this, ... 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. As an example, let’s create a simple SwiftUI wrapper for UITextView as the basis of a rich text editor. Th... Read more >>

Importing an image into SwiftUI using PHPickerViewController

Project In order to bring this project to life, we need to let the user select a photo from their library, then display it in ContentView. I’ve already shown you how this all works, so if you followed the introductory chapters... Read more >>

Special effects in SwiftUI: blurs, blending, and more

Project ...trol 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 way one view is rendered on top of another. The default mode is .normal, which just draws the pixels from the new view onto whatever is behind, but there are lots of options for controlling color and opacity. As a... 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 pl... Read more >>

Introducing MVVM into your SwiftUI project

Project ... 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 software architecture, or the more grandiose name an architectural design pattern – really it’s just a particular way of structuring your code. The pattern we’re going to lo... 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 you do ge... Read more >>

Using Touch ID and Face ID with SwiftUI

Project The vast majority of Apple’s devices come with biometric authentication as standard, which means they use fingerprint, facial, and even iris recognition to unlock. This functionality is available 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, b... Read more >>

Importing an image into SwiftUI using PhotosPicker

Project In order to bring this project to 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 compa... 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() .environment(\.managedObjectContext, yourCoreDataContext) That passes our view context directly into ContentView as environment data, which means we c... 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 spring, which means iOS will start the animation slow, then make it pick up speed until... Read more >>

SwiftUI’s built-in shapes

Example Code ... .frame(width: 100, height: 50) } } } That draws all five shapes: two at 200x200 and three at 100x50. However, because the drawing behavior of the shapes is different you’ll see all five shapes visible in the output: Rectangle draws a box at the exact dimensions you specify. RoundedRectangle does the same, except now you can round the corners by a c... Read more >>

How to add in-app purchases in SwiftUI

Example Code ...ort StoreKit, you can use StoreView, SubscriptionStoreView, and ProductView to present in-app purchases to your users, including handling the process of starting the purchase. This still leaves a fair amount of StoreKit work for you to do, including processing the actual purchase transactions and so on, but I wouldn’t rule out Apple requiring apps to use this standardized i... Read more >>

How to use programmatic navigation in SwiftUI

Example Code ...lly 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 list row. Important: There are two approaches to programmatic navigation: the newer, more powerful option available from iOS 16 and later, or the older, simpler option available available in earlier re... Read more >>

Making a SwiftUI view searchable

Project iOS can add a search bar to our views using the searchable() modifier, and we can bind a string property to it to filter our data as the user types. To see how this works, try this simple example: struct ContentView: View { @State private var searchText = "" var body: some View { NavigationView { Text("Searching for \(searchText)")... Read more >>

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

Project ... back to the foreground, and if you put those two together it allows us to make sure our app pauses and resumes work depending on whether the user can see it right now or not. This is done using three steps: Adding a new property to watch an environment value called scenePhase. Using onChange() to watch for the scene phase changing. Responding to the new scene phase somehow.... Read more >>

Handling voice input in SwiftUI

Project Once you've made sure your app works well with Voiceover, a great next step is to make sure it handles voice input too – that you work well with Apple's Voice Control technology, which lets users control your app by speaking to it. Voice Input lets users activate controls ... Read more >>

Relationships with SwiftData, SwiftUI, and @Query

Project ...ome in all sorts of forms. SwiftData does a good job of forming these relationships automatically as long as you tell it what you want, although there's still some room for surprises! Let's try them out now. We already have the following User model: @Model class User { var name: String var city: String var joinDate: Date init(name: String, city: String, joinD... 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, but it’s extremely helpful for the times when you can see a view is reinvoking its body property but you’re not sure why. Th... Read more >>

Formatting interpolated strings in SwiftUI

Example Code ...e going to add a totalPrice computed property to our type, which will calculate the value of their tip, add it to the total for their order, and return that amount. Please add this to CheckoutView now: var totalPrice: String { let total = Double(order.total) let tipValue = total / 100 * Double(tipAmount) return (total + tipValue).formatted(.currency(code: "USD")) ... Read more >>

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.