• Neu
Catalan | SwiftUI Cookbook | E-Book | www.sack.de
E-Book

E-Book, Englisch, 650 Seiten

Reihe: Packt Publishing

Catalan SwiftUI Cookbook

Build Modern iOS Apps with Practical Recipes and Hands-On Sample Projects
1. Auflage 2026
ISBN: 978-1-80666-376-7
Verlag: Packt Publishing
Format: EPUB
Kopierschutz: 0 - No protection

Build Modern iOS Apps with Practical Recipes and Hands-On Sample Projects

E-Book, Englisch, 650 Seiten

Reihe: Packt Publishing

ISBN: 978-1-80666-376-7
Verlag: Packt Publishing
Format: EPUB
Kopierschutz: 0 - No protection



SwiftUI Cookbook is a practical guide to building modern iOS apps with SwiftUI. Fully updated for iOS 27, this edition introduces a beginner-friendly structure while retaining the cookbook approach developers love.
Starting with the fundamentals of SwiftUI, you'll learn how to create responsive layouts, build reusable views, manage navigation flows, and design interactive forms and lists. You'll then master data flow with the Observation framework, persist data with SwiftData, fetch remote content with async/await, and learn to debug, test, and profile your apps.
The book also explores advanced topics such as custom layouts, deep linking, animations, Canvas drawing, Swift Charts, WebView integration, rich text, Liquid Glass visual effects, and on-device Apple Intelligence with Foundation Models and Image Playground. Every recipe is built around a focused, practical sample app, with all the code available for download.
Whether you are new to SwiftUI or an experienced Apple developer, this book will help you build responsive, visually polished, and production-ready apps using the latest tools and frameworks from Apple.

Catalan SwiftUI Cookbook jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


1


SwiftUI Essentials


When I first started building iOS apps, setting up even a simple screen meant writing dozens of lines of boilerplate code or spending hours in Interface Builder. SwiftUI changed that. Instead of telling the system how to construct each element step by step, we describe what we want on screen, and the framework takes care of the rest. After years of annual updates, SwiftUI has matured into the standard way to build apps across Apple's platforms, and I use it in every project I work on.

In practice, SwiftUI's declarative approach means we compose our screens from small, reusable pieces, arranged inside layout containers and fine-tuned with modifiers. When data changes, SwiftUI figures out which parts of the screen need to update and redraws them for us. The recipes in this chapter introduce these core pieces and show how they fit together in working apps.

In this first chapter, we will get hands-on with the essentials. We will start by learning how to display text and images, and how to arrange views using , , and . From there, we will explore buttons and navigation with and , discovering how to style buttons and move between screens. We will then dive into input controls such as , , , , and , along with SF Symbols (San Francisco Symbols, named after Apple's San Francisco system font), Apple's library of over 6,000 system icons that scale and color alongside text. Finally, we will learn how to bridge UIKit components into SwiftUI using and , a technique that opens up the entire UIKit ecosystem from within our SwiftUI apps.

By the end of the chapter, you should feel comfortable with SwiftUI's core building blocks and, more importantly, with the way those pieces fit together when you build real screens.

We will cover these topics in the following recipes:

  • Basic Views and Layout
  • Buttons and Navigation
  • Pickers, Toggles, and SF Symbols
  • UIKit Interoperability Basics

Download the code bundle and the PDF version of this book

Your purchase includes a DRM-free PDF copy of this book, the code bundle, and a range of exclusive benefits. To unlock everything, follow the section in the .

Technical requirements


The code in this chapter is based on Xcode 27.0 and iOS 27.0. You can download and install the latest version of Xcode from the App Store. All the code examples for this chapter can be found on GitHub at https://x.swiftuicookbook.com/ch01.

Basic Views and Layout


The best way to understand SwiftUI is to build something with it. In this first recipe, we will construct a weather profile card from scratch, starting with plain text and progressively adding images, layout containers, modifiers, and a layered background. Along the way, we will see how views nest inside each other to form the screen, and how modifiers control their appearance and sizing.

The finished card displays a city name, a weather summary, temperatures, and an icon, but the real goal is bigger than the finished UI. This small example gives us a compact way to practice composition, nesting, and modifier order without introducing unnecessary complexity.

Getting ready


You will need a new SwiftUI iOS app named BasicViews. Follow these steps to create it:

  1. Open Xcode and click on the New Project button. Alternatively, select File > New > Project from the menu bar.
  2. From the displayed menu, select Choose Template….
  3. Select the iOS tab, choose the App template, and click Next.
  4. Set the product name to BasicViews, make sure the interface is set to SwiftUI and the language is set to Swift, and leave Testing System and Storage set to None.
  5. Click Next, choose a folder for the project (you can leave Create Git Repository on my Mac unchecked for these recipes), and click Create.

This is the same process you will follow to create an Xcode project for every recipe in this book, unless otherwise noted.

How to do it…


We will build the card the same way I usually teach SwiftUI on a team: start with the smallest visible pieces, verify each step, and only then layer on layout and styling. That approach keeps the view hierarchy understandable from the beginning. These are the steps:

  1. Open the file. is the root view Xcode generates for every new app, and the struct displays it on launch, which is why we start here, and why you will meet this name in every recipe; it is as fundamental to a SwiftUI app as the property is to a view. Replace the content of with a containing a couple of views. The should look like the following:
  2. Use the preview canvas in live mode to confirm the baseline layout. At this point, you should see two centered lines of text. I like verifying early, because once modifiers and nested containers start piling up, small mistakes become harder to spot. You can also check the corresponding step files in the book's GitHub repository to compare your code at each stage.
  3. Next, add a bit of hierarchy to the text with font and weight modifiers, so the city reads as the primary element and the weather condition reads as supporting information:
  4. Now, let's add an image. Download the file from the folder in the book's GitHub repository, then drag it into the asset catalog () in the Xcode Project Navigator. Add the weather image above the text, so the card starts to feel like a composed interface rather than a loose stack of labels. The string in must match the asset's name exactly, including its spaces and capitalization:
  5. Let's improve the layout by adding spacing and padding. We will also switch to the -based syntax, which is type-safe and provides compile-time checking for asset names:
  6. With the vertical structure in place, we can bring in an to lay out the temperature information horizontally and make the card feel more like a real weather summary:
  7. Add a between the city info and the temperature row. A draws a thin horizontal line when placed inside a :
  8. Now, expand the temperature row to three columns (Low, Current, and High) and replace the fixed spacing with views, so the columns distribute themselves naturally across the available width. Replace the with the following, and delete the modifier after the outer . The row now carries its own horizontal and bottom padding, and leaving the unpadded lets the header we build in step 10 reach the edges of the card:



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.