Home
Books & eBooks
Video Courses
Newsletter
Contact
HOME
BOOKS
VIDEO COURSES
NEWSLETTER
CONTACT
SwiftUI for Masterminds
How to take advantage of SwiftUI to create insanely great apps for iPhones, iPads and Macs
6th Edition
February 2026
ISBN: 978-1-0699942-0-2
Buy Now
Examples and Projects
Download the source code in TXT format, access the complete Xcode projects, or open the specific examples you want to review using the links below.
Download TXT Files
305.0 KBytes
Download
Download Projects
1.3 GBytes
Download
Chapter 1 - App Development
There are no Examples in this Chapter
Chapter 2 - SwiftUI Framework
Listing 2-1: Initializing the app
Listing 2-2: Defining a structure that conforms to the View protocol
Listing 2-3: Generating multiple previews
Listing 2-4: Displaying values with a Text view
Listing 2-5: Formatting a value for a Text view
Listing 2-6: Displaying a date with a Text view
Listing 2-7: Displaying a timer with a Text view
Listing 2-8: Applying modifiers to a view
Listing 2-9: Using the system font
Listing 2-10: Applying multiple styles to a text
Listing 2-11: Nesting Text views
Listing 2-12: Styling the font
Listing 2-13: Formatting text
Listing 2-14: Truncating text
Listing 2-15: Using standard fonts
Listing 2-16: Using custom fonts
Listing 2-17: Assigning a fixed size to a view
Listing 2-18: Creating flexible containers
Listing 2-19: Adding padding to a view
Listing 2-20: Assigning a specific padding for each side
Listing 2-21: Assigning padding with Edge values
Listing 2-22: Implementing Color views
Listing 2-23: Defining the color with RGB values
Listing 2-24: Assigning a dynamic color
Listing 2-25: Assigning a custom color
Listing 2-26: Assigning a color to the text of a Text view
Listing 2-27: Assigning a background color to a Text view
Listing 2-28: Assigning a background color to a view with a padding
Listing 2-29: Assigning a border to the view
Listing 2-30: Displaying a view in front of another view
Listing 2-31: Applying a predefined gradient to a view
Listing 2-32: Blending colors
Listing 2-33: Applying a material
Listing 2-34: Applying a material to the view's content
Listing 2-35: Displaying an image
Listing 2-36: Loading an image from the ImageResource structure
Listing 2-37: Clipping the image
Listing 2-38: Resizing the image
Listing 2-39: Resizing an image to fit the view
Listing 2-40: Resizing and clipping the image to fill the view
Listing 2-41: Resizing image to fill the container
Listing 2-42: Applying style modifiers to an Image view
Listing 2-43: Applying visual effects to an Image view
Listing 2-44: Displaying SF symbols
Listing 2-45: Styling a symbol
Listing 2-46: Assigning a variant to a symbol
Listing 2-47: Displaying multicolor symbols
Listing 2-48: Displaying a multicolor symbol with custom colors
Listing 2-49: Displaying a variable SF Symbol
Listing 2-50: Displaying a variable multicolor SF Symbol
Listing 2-51: Displaying a text with an SF Symbol
Listing 2-52: Performing a task when the view appears
Listing 2-53: Applying custom modifiers
Listing 2-54: Customizing a custom modifier
Listing 2-55: Creating a vertical stack of views
Listing 2-56: Adding a space between the views
Listing 2-57: Creating a horizontal stack of views
Listing 2-58: Aligning a horizontal stack of views
Listing 2-59: Nesting stacks
Listing 2-60: Aligning the views with a flexible space
Listing 2-61: Aligning the views to the left and the top
Listing 2-62: Aligning the views in a stack of custom size
Listing 2-63: Creating a ZStack
Listing 2-64: Setting the Z index of a view
Listing 2-65: Assigning modifiers to the stack and its content
Listing 2-66: Ignoring the safe area
Listing 2-67: Expanding the safe area
Listing 2-68: Arranging the views with priorities by default
Listing 2-69: Assigning a higher priority to a view
Listing 2-70: Defining a view with a fixed size
Listing 2-71: Arranging the views in groups
Listing 2-72: Assigning different views to the body property
Listing 2-73: Defining a grid layout
Listing 2-74: Defining a multicolumn cell
Listing 2-75: Embedding a grid within another grid
Listing 2-76: Wrapping views in an AnyView view
Listing 2-77: Constructing views with the @ViewBuilder property wrapper
Listing 2-78: Constructing reusable views with the @ViewBuilder property wrapper
Listing 2-79: Returning an empty view
Listing 2-80: Additional views
Listing 2-81: Responding to updates in the states of the environment
Listing 2-82: Activating dark mode in the preview from code
Listing 2-83: Adding custom properties to the environment
Chapter 3 - Declarative User Interface
Listing 3-1: Defining a state
Listing 3-2: Defining multiple states
Listing 3-3: Defining bidirectional binding
Listing 3-4: Using @Binding properties
Listing 3-5: Creating a binding with an immutable value
Listing 3-6: Defining a state property for a preview
Listing 3-7: Implementing Button views
Listing 3-8: Using functions to organize the code
Listing 3-9: Referencing a method
Listing 3-10: Adding and removing views from the interface
Listing 3-11: Disabling a button
Listing 3-12: Styling buttons
Listing 3-13: Assigning a role
Listing 3-14: Liquid glass buttons
Listing 3-15: Implementing large buttons
Listing 3-16: Changing the shape of a button
Listing 3-17: Buttons with SF Symbols
Listing 3-18: Defining custom styles for the button
Listing 3-19: Configuring a text field
Listing 3-20: Styling a text field
Listing 3-21: Responding to the Done button
Listing 3-22: Responding to changes in focus
Listing 3-23: Closing the keyboard
Listing 3-24: Checking the values before storing
Listing 3-25: Disabling the button
Listing 3-26: Controlling user's input
Listing 3-27: Accepting only integer numbers
Listing 3-28: Defining a multiline text field
Listing 3-29: Selecting text
Listing 3-30: Using a secure text field
Listing 3-31: Implementing a text editor
Listing 3-32: Customizing a text editor
Listing 3-33: Selecting text in a text editor
Listing 3-34: Creating attributed text
Listing 3-35: Allowing users to generate attributed text
Listing 3-36: Applying attributes to the selected text
Listing 3-37: Applying attributes to the current font
Listing 3-38: Applying attributes to the text
Listing 3-39: Manually applying attributes to ranges of characters
Listing 3-40: Applying attributes to specific characters
Listing 3-41: Inspecting runs to find if they apply a specific attribute
Listing 3-42: Implementing a Toggle
Listing 3-43: Including a subtitle
Listing 3-44: Defining a custom label for the Toggle view
Listing 3-45: Implementing a toggle button
Listing 3-46: Creating a basic slider
Listing 3-47: Designing a slider
Listing 3-48: Customizing the slider
Listing 3-49: Customizing the slider for Macs
Listing 3-50: Showing progress
Listing 3-51: Showing an activity indicator
Listing 3-52: Creating a stepper
Listing 3-53: Modifying the interface when the value is incremented or decremented
Listing 3-54: Defining a group of views
Listing 3-55: Storing our data in an observable object
Listing 3-56: Working with an observable object
Listing 3-57: Initializing the properties of an observable object
Listing 3-58: Initializing properties when the view appears
Listing 3-59: Disabling observation for a property
Listing 3-60: Updating the views manually
Listing 3-61: Assigning the observable object to the view's environment
Listing 3-62: Getting a reference to the observable object from the environment
Chapter 4 - Lists
Listing 4-1: Creating a dynamic list of views
Listing 4-2: Creating a list with a standard design
Listing 4-3: Defining a model to work with lists of views
Listing 4-4: Injecting the model into the environment
Listing 4-5: Creating a list of views with data from the model
Listing 4-6: Creating a scrollable list of views
Listing 4-7: Configuring the scroll view
Listing 4-8: Scrolling the list of views horizontally
Listing 4-9: Adapting the size of the views to the container
Listing 4-10: Scrolling the content page by page
Listing 4-11: Scrolling two views at a time
Listing 4-12: Defining each view as a scroll target
Listing 4-13: Scrolling the content programmatically
Listing 4-14: Applying a visual effect to the transition
Listing 4-15: Applying multiple visual effects to the transition
Listing 4-16: Creating a grid with a fixed number of items
Listing 4-17: Defining flexible items
Listing 4-18: Defining adaptive items
Listing 4-19: Creating a list of views with the List view
Listing 4-20: Creating a plain list
Listing 4-21: Customizing the rows
Listing 4-22: Mixing static and dynamic content in a list
Listing 4-23: Dividing the content into sections
Listing 4-24: Configuring the section separators
Listing 4-25: Configuring the list from the environment
Listing 4-26: Providing an ordered list of values
Listing 4-27: Adding an index to navigate the list
Listing 4-28: Deleting rows
Listing 4-29: Activating the edit mode
Listing 4-30: Moving rows
Listing 4-31: Selecting a row
Listing 4-32: Selecting multiple rows
Listing 4-33: Customizing the edit mode
Listing 4-34: Customizing the selection
Listing 4-35: Storing the selection in the model
Listing 4-36: Defining custom swipe actions
Listing 4-37: Implementing a custom button to delete the rows
Listing 4-38: Refreshing the list
Listing 4-39: Defining the model to create a hierarchical list
Listing 4-40: Displaying a hierarchical list
Listing 4-41: Implementing an OutlineGroup view
Listing 4-42: Defining a model to test tables
Listing 4-43: Creating a table with multiple columns
Listing 4-44: Defining the rows manually
Listing 4-45: Sorting the values by column
Listing 4-46: Sorting only the calories
Listing 4-47: Allowing the user to select items in a table
Listing 4-48: Using a context menu to process a row
Listing 4-49: Defining the content of a column with a Toggle view
Listing 4-50: Defining a custom sort comparator
Listing 4-51: Sorting Boolean values on a table
Listing 4-52: Defining a model with hierarchical data
Listing 4-53: Disclosing hierarchical data on a table
Listing 4-54: Defining a picker
Listing 4-55: Selecting an initial value
Listing 4-56: Listing values by index
Listing 4-57: Implementing a segmented picker
Listing 4-58: Defining a DatePicker to select a date
Listing 4-59: Limiting the DatePicker to a range of values
Listing 4-60: Presenting a picker with a spinning wheel
Listing 4-61: Picking multiple dates
Listing 4-62: Defining a form
Listing 4-63: Defining a custom label for a form
Listing 4-64: Styling a form
Listing 4-65: Disclosing controls
Listing 4-66: Defining a custom container
Listing 4-67: Implementing a custom container
Listing 4-68: Applying different styles to the views in a custom container
Listing 4-69: Adding a container value
Listing 4-70: Modifying a container value
Listing 4-71: Using container values
Listing 4-72: Changing the container value of a view
Chapter 5 - Navigation
Listing 5-1: Initiating a navigation stack
Listing 5-2: Setting the title mode
Listing 5-3: Adding a button to the navigation bar
Listing 5-4: Adding multiple buttons to a toolbar
Listing 5-5: Grouping multiple related buttons
Listing 5-6: Adding buttons to the bottom toolbar
Listing 5-7: Defining the buttons intent
Listing 5-8: Creating a popup menu
Listing 5-9: Creating submenus
Listing 5-10: Customizing the navigation bar
Listing 5-11: Customizing the items in a navigation bar
Listing 5-12: Creating our own navigation bar
Listing 5-13: Filtering the data in the model
Listing 5-14: Displaying a search bar
Listing 5-15: Moving the search bar to the navigation bar
Listing 5-16: Minimizing the search bar
Listing 5-17: Activating the search field
Listing 5-18: Performing the search only when the Return/Done key is pressed
Listing 5-19: Suggesting terms to the user
Listing 5-20: Cancelling the search programmatically
Listing 5-21: Adding scope buttons
Listing 5-22: Searching by title and author
Listing 5-23: Adding tokens
Listing 5-24: Filtering books by author
Listing 5-25: Including a navigation link
Listing 5-26: Defining a second view
Listing 5-27: Creating a custom back button
Listing 5-28: Selecting rows with a navigation link
Listing 5-29: Defining a Detail view
Listing 5-30: Using custom navigation
Listing 5-31: Adding and removing views from the path
Listing 5-32: Removing a view from the path
Listing 5-33: Controlling the navigation path from the model
Listing 5-34: Controlling the navigation path from the initial view
Listing 5-35: Adding views to the navigation path programmatically
Listing 5-36: Returning to different views
Listing 5-37: Working with the navigation path from the model
Listing 5-38: Opening a view with a zoom transition
Listing 5-39: Displaying a sheet
Listing 5-40: Defining the view for the sheet
Listing 5-41: Assigning a predefined height
Listing 5-42: Assigning a custom background
Listing 5-43: Declaring the size of the sheet
Listing 5-44: Presenting a sheet for every value on the list
Listing 5-45: Editing a book
Listing 5-46: Presenting the inspector
Listing 5-47: Defining the size of the inspector
Listing 5-48: Showing a popover
Listing 5-49: Defining the content of the popover
Listing 5-50: Displaying an alert view
Listing 5-51: Defining an Alert view with multiple buttons
Listing 5-52: Defining an action sheet
Listing 5-53: Defining a tip
Listing 5-54: Presenting a tip
Listing 5-55: Presenting a tip in a popover
Listing 5-56: Showing the tips for testing
Listing 5-57: Invalidating a tip
Listing 5-58: Showing the tip only once
Listing 5-59: Adding actions to a tip
Listing 5-60: Performing an action
Listing 5-61: Defining a TabView view with two tabs
Listing 5-62: Displaying a badge on a tab
Listing 5-63: Selecting the Settings view
Listing 5-64: Minimizing the tabs
Listing 5-65: Adding an accessory view
Listing 5-66: Adding a search tab
Listing 5-67: Configuring the TabView view to show content in pages
Listing 5-68: Expanding the TabView view with a sidebar
Listing 5-69: Adding a header to the sidebar
Listing 5-70: Creating a section for the sidebar
Listing 5-71: Customizing the TabView view
Listing 5-72: Designing a TabView view to manage books
Listing 5-73: Updating the model
Listing 5-74: Designing the rows according to the app's configuration
Listing 5-75: Configuring the app
Listing 5-76: Searching for books
Listing 5-77: Defining a two-column split view
Listing 5-78: Defining the view for the left column
Listing 5-79: Defining the Detail view
Listing 5-80: Showing an item by default
Listing 5-81: Enabling navigation in the right column
Listing 5-82: Creating a navigation path for the right column
Listing 5-83: Expanding the cover
Listing 5-84: Adding navigation to the left column
Listing 5-85: Opening a view on the left column
Listing 5-86: Providing the list of authors
Listing 5-87: Defining a three-column layout
Listing 5-88: Showing the authors
Listing 5-89: Showing the books
Listing 5-90: Hiding columns programmatically
Listing 5-91: Configuring the columns
Chapter 6 - Data Storage
Listing 6-1: Storing and reading values from User Defaults
Listing 6-2: Adapting the interface to the app's settings
Listing 6-3: Modifying the app's settings
Listing 6-4: Defining a SwiftData model
Listing 6-5: Creating the container
Listing 6-6: Controlling the navigation path from an observable object
Listing 6-7: Fetching books from the database
Listing 6-8: Storing a book in the database
Listing 6-9: Storing unique values
Listing 6-10: Using the #Unique macro to avoid duplicates
Listing 6-11: Creating indexes for better performance
Listing 6-12: Creating a second model to store the authors
Listing 6-13: Creating a relationship with the Author class
Listing 6-14: Defining the relationship in the Book class
Listing 6-15: Defining the relationship in the Author class
Listing 6-16: Controlling the values selected by the user from the model
Listing 6-17: Opening additional views for navigation
Listing 6-18: Assigning an author to a book
Listing 6-19: Listing the authors
Listing 6-20: Adding new authors
Listing 6-21: Displaying the author's name
Listing 6-22: Including all the models in the container
Listing 6-23: Deleting objects
Listing 6-24: Sorting objects
Listing 6-25: Sorting books by author and year
Listing 6-26: Sorting with a lexical comparator
Listing 6-27: Filtering books by year
Listing 6-28: Filtering books by author and year
Listing 6-29: Filtering books by text
Listing 6-30: Defining a dynamic query
Listing 6-31: Defining a dynamic query
Listing 6-32: Searching books by title
Listing 6-33: Fetching objects manually
Listing 6-34: Counting objects
Listing 6-35: Checking for duplicates
Listing 6-36: Providing sample data for the previews
Listing 6-37: Implementing a custom container in the preview
Listing 6-38: Preparing the selectedBook property to add new books
Listing 6-39: Opening the view to edit a book
Listing 6-40: Editing a book
Listing 6-41: Storing images externally
Listing 6-42: Displaying an image from a UIImage object
Listing 6-43: Displaying the image in the DetailView view
Listing 6-44: Converting a UIImage object into data
Listing 6-45: Creating Book objects with images from the Asset Catalog
Listing 6-46: Sorting the books
Listing 6-47: Displaying the books in sections
Listing 6-48: Storing the letters for the sections
Listing 6-49: Adding the relationship to sort the books by letter
Listing 6-50: Getting the SortLetters object that correspond to the book
Listing 6-51: Listing books in alphabetical sections
Listing 6-52: Listing books in alphabetical sections
Listing 6-53: Defining a Codable structure
Listing 6-54: Storing and decoding data
Listing 6-55: Encoding data
Listing 6-56: Displaying encoded data
Listing 6-57: JSON file
Listing 6-58: Decoding with JSON
Listing 6-59: Encoding with JSON
Listing 6-60: Saving files
Listing 6-61: Opening a sheet to add files to the model
Listing 6-62: Creating new files
Listing 6-63: Getting the list of files
Listing 6-64: Listing the files created by the user
Listing 6-65: Reading the content of a file
Listing 6-66: Allowing the user to open a file
Listing 6-67: Displaying the contents of a file
Listing 6-68: Deleting a file
Listing 6-69: Allowing the user to delete files
Listing 6-70: Storing text in a file
Listing 6-71: Editing the content of a file
Listing 6-72: Loading a file from the bundle
Listing 6-73: Displaying the content of a file stored in the bundle
Listing 6-74: Defining a document model
Listing 6-75: Creating a Document app
Listing 6-76: Editing the document
Listing 6-77: Exporting a document
Listing 6-78: Importing a document
Chapter 7 - Multiplatform Applications
Listing 7-1: Detecting the platform before compiling
Listing 7-2: Defining a multiplatform interface
Listing 7-3: Detecting the version of the operating system
Listing 7-4: Adding a menu to the menu bar
Listing 7-5: Assigning a keyboard shortcut to a menu option
Listing 7-6: Adding options to a standard menu
Listing 7-7: Removing options
Listing 7-8: Adding a submenu
Listing 7-9: Defining a property in the model to store the index of the selected option
Listing 7-10: Selecting options
Listing 7-11: Defining a state to enable and disable a menu option
Listing 7-12: Enabling and disabling a menu option
Listing 7-13: Defining a TextField view to enable and disable the option
Listing 7-14: Storing a focus state in the FocusedValues structure
Listing 7-15: Passing the focus state to the FocusedValues structure
Listing 7-16: Disabling a menu option according to the focus state of a view
Listing 7-17: Defining a two-column interface for a multi-platform application
Listing 7-18: Adding items to the toolbar for a multi-platform application
Listing 7-19: Hiding the toolbar on the Mac
Listing 7-20: Hiding only the toolbar on the Mac
Listing 7-21: Showing a tooltip for a button
Listing 7-22: Showing suggestions for a text field
Listing 7-23: Defining a model to test alternate backgrounds
Listing 7-24: Creating a list with alternate background
Listing 7-25: Opening an auxiliary window
Listing 7-26: Opening a window programmatically
Listing 7-27: Closing a window programmatically
Listing 7-28: Configuring the window to adopt the size of the content
Listing 7-29: Assigning a fixed size to a view
Listing 7-30: Assigning a position by default
Listing 7-31: Defining a custom position and size for the window
Listing 7-32: Disabling window controls
Listing 7-33: Applying a custom design to a window
Listing 7-34: Dragging a view
Listing 7-35: Defining a Settings scene
Listing 7-36: Inserting a control in the system's menu bar
Listing 7-37: Defining the control to open a view
Listing 7-38: Detecting changes in orientation
Listing 7-39: Using a GeometryReader to detect orientation
Listing 7-40: Reading the position of the GeometryReader view
Listing 7-41: Reading the position and size of a view
Listing 7-42: Setting and reading preferences
Listing 7-43: Aligning images to the center with standard values
Listing 7-44: Aligning an image to the center with custom values
Listing 7-45: Aligning all images to the center with custom values
Listing 7-46: Defining custom alignment guides
Listing 7-47: Aligning views with custom alignment guides
Listing 7-48: Defining a custom layout
Listing 7-49: Selecting a layout
Chapter 8 - Graphics & Animations
Listing 8-1: Drawing standard shapes
Listing 8-2: Filling a shape with a color
Listing 8-3: Defining a border
Listing 8-4: Defining a custom border
Listing 8-5: Combining shapes with other views
Listing 8-6: Assigning a shape as the background of a button
Listing 8-7: Defining a linear gradient
Listing 8-8: Defining a linear gradient with custom stops
Listing 8-9: Defining a circular gradient
Listing 8-10: Defining a mesh gradient
Listing 8-11: Adding a shadow to a shape
Listing 8-12: Filling a shape with an image
Listing 8-13: Defining a custom path
Listing 8-14: Combining lines and arcs
Listing 8-15: Combining lines and ellipses
Listing 8-16: Creating complex curves
Listing 8-17: Creating a custom shape view
Listing 8-18: Implementing custom shape views
Listing 8-19: Displacing an image
Listing 8-20: Rotating the image
Listing 8-21: Clipping the image
Listing 8-22: Adding a border to an irregular shape
Listing 8-23: Rotating a shape
Listing 8-24: Inverting a shape with the scale() modifier
Listing 8-25: Trimming a path
Listing 8-26: Creating concentric views
Listing 8-27: Assigning a concentric shape to an image
Listing 8-28: Concentric shapes with different corners
Listing 8-29: Concentric shapes with uniform corners
Listing 8-30: Creating an image from a view
Listing 8-31: Drawing an image on the canvas
Listing 8-32: Drawing an image of a custom size
Listing 8-33: Drawing shapes and text
Listing 8-34: Rotating the canvas
Listing 8-35: Rotating an image
Listing 8-36: Performing multiple transformations
Listing 8-37: Preparing images
Listing 8-38: Clipping the canvas
Listing 8-39: Applying filters to the graphics
Listing 8-40: Providing the data for a chart
Listing 8-41: Visualizing data with a bar chart
Listing 8-42: Visualizing data with a line chart
Listing 8-43: Defining a custom scale for the y axis
Listing 8-44: Assigning different styles based on a value
Listing 8-45: Representing the values with different types of marks
Listing 8-46: Drawing a line in the plot area
Listing 8-47: Selecting a value
Listing 8-48: Visualizing large datasets with a point plot
Listing 8-49: Plotting a mathematical function
Listing 8-50: Representing the values with different types of marks
Listing 8-51: Visualizing two series of values
Listing 8-52: Visualizing two series of values with a bar chart
Listing 8-53: Defining the positions of the bars
Listing 8-54: Scrolling the chart
Listing 8-55: Defining the coordinates values for a 3D chart
Listing 8-56: Creating a 3D chart
Listing 8-57: Changing the orientation of a 3D chart
Listing 8-58: Plotting a mathematical function in 3D
Listing 8-59: Animating a view
Listing 8-60: Applying a linear animation
Listing 8-61: Declaring a specific duration
Listing 8-62: Configuring the animation
Listing 8-63: Defining a custom animation
Listing 8-64: Animating multiple states at a time
Listing 8-65: Defining an animatable shape
Listing 8-66: Animating a shape
Listing 8-67: Updating the interface
Listing 8-68: Animating the canvas
Listing 8-69: Creating a real animation
Listing 8-70: Adding and removing a view with a transition
Listing 8-71: Defining an asymmetric transition
Listing 8-72: Combining transitions
Listing 8-73: Customizing the transition
Listing 8-74: Coordinating transitions
Listing 8-75: Coordinating views
Listing 8-76: Animating an SF Symbol
Listing 8-77: Animating an SF Symbol when a value changes
Listing 8-78: Configuring animations
Listing 8-79: Scaling a symbol
Listing 8-80: Removing a symbol from the screen
Listing 8-81: Adapting the layout to the effect
Listing 8-82: Replacing a symbol
Listing 8-83: Applying the liquid glass effect to a view
Listing 8-84: Applying a clear liquid glass effect
Listing 8-85: Applying a different shape to the liquid glass effect
Listing 8-86: Making the view interactive
Listing 8-87: Applying the liquid glass effect to a group of views
Listing 8-88: Joining views with the Liquid Glass effect
Listing 8-89: Animating views with Liquid Glass effect
Chapter 9 - Gestures
Listing 9-1: Detecting a tap gesture on an image
Listing 9-2: Showing the image
Listing 9-3: Detecting a long press gesture
Listing 9-4: Disabling the tap gesture
Listing 9-5: Defining the shape of the content
Listing 9-6: Defining a TapGesture recognizer
Listing 9-7: Defining a LongPressGesture recognizer
Listing 9-8: Controlling the states of a gesture with an enumeration
Listing 9-9: Defining a MagnificationGesture recognizer
Listing 9-10: Determining a minimum and a maximum scale
Listing 9-11: Defining a RotationGesture recognizer
Listing 9-12: Allowing the user to drag an image
Listing 9-13: Providing a custom preview for the gesture
Listing 9-14: Dropping images into an Image view
Listing 9-15: Providing feedback to the user
Listing 9-16: Dragging custom values
Listing 9-17: Using a custom content type
Listing 9-18: Dragging and dropping custom values
Listing 9-19: Pasting values from the clipboard
Listing 9-20: Copying and pasting values from the clipboard
Chapter 10 - MapKit
Listing 10-1: Displaying a map
Listing 10-2: Displaying a hybrid map
Listing 10-3: Selecting points of interest
Listing 10-4: Configuring the map from the data model
Listing 10-5: Zooming in on a region of the map
Listing 10-6: Showing the current latitude and longitude
Listing 10-7: Disabling panning
Listing 10-8: Defining the boundaries for the camera
Listing 10-9: Applying the boundaries to the map
Listing 10-10: Adding markers to the map
Listing 10-11: Displaying annotations
Listing 10-12: Drawing a circle over the labels
Listing 10-13: Drawing a line
Listing 10-14: Finding places with Local Search
Listing 10-15: Searching for places
Listing 10-16: Selecting markers
Listing 10-17: Showing a callout with additional information
Listing 10-18: Opening a sheet with additional information
Listing 10-19: Displaying map controls
Listing 10-20: Creating custom controls
Listing 10-21: Creating a Look Around preview
Listing 10-22: Creating a Look Around preview
Listing 10-23: Presenting the Look Around sheet
Listing 10-24: Calculating a route
Listing 10-25: Displaying a route
Listing 10-26: Determining a location on a map
Listing 10-27: Finding the street address from map coordinates
Listing 10-28: Allowing the user to select a location to find an address
Listing 10-29: Finding the map coordinates of an address
Listing 10-30: Allowing the user to find an address on the map
Listing 10-31: Asking permission and responding to errors
Listing 10-32: Requesting authorization and showing the user's location
Listing 10-33: Implementing the user location button
Chapter 11 - Web
Listing 11-1: Opening a website
Listing 11-2: Opening URLs from code
Listing 11-3: Processing the user's URLs
Listing 11-4: Loading a website with a WebView view
Listing 11-5: Initializing a WebPage object for navigation
Listing 11-6: Allowing the user to load a website
Listing 11-7: Updating the URL in the text field
Listing 11-8: Moving through the navigation history
Listing 11-9: Loading a remote document from the model
Listing 11-10: Displaying the document's content
Listing 11-11: Loading a JSON document
Listing 11-12: Listing the values from the document
Chapter 12 - Notifications
Listing 12-1: Listening to notifications from the model
Listing 12-2: Listening to notifications
Listing 12-3: Sending notifications
Listing 12-4: Adding information to the notification
Listing 12-5: Reading the value in the notification
Listing 12-6: Cancelling the task
Listing 12-7: Interface to test the keyboard
Listing 12-8: Scrolling the interface to make room for the keyboard
Listing 12-9: Listening to keyboard notifications
Listing 12-10: Modifying the interface when the keyboard state changes
Listing 12-11: Sending notifications
Listing 12-12: Scheduling a notification
Listing 12-13: Playing a sound
Listing 12-14: Attaching an image to a notification
Listing 12-15: Defining a delegate for the User Notification Center
Listing 12-16: Showing notifications while the app is running
Listing 12-17: Defining an observable property for KVO
Listing 12-18: Observing a property
Listing 12-19: Working with a KVO property
Listing 12-20: Detecting changes in the app's state
Listing 12-21: Defining a custom app delegate
Listing 12-22: Assigning the app delegate from a SwiftUI application
Listing 12-23: Defining a custom Scene delegate
Listing 12-24: Configuring a Scene
Listing 12-25: Modifying the model from the app delegate
Chapter 13 - Framework Integration
Listing 13-1: Preparing a UIKit view to work with SwiftUI
Listing 13-2: Showing a UIKit view within a SwiftUI view
Listing 13-3: Sending and receiving values from the SwiftUI view
Listing 13-4: Receiving and sending values to a UIKit view
Listing 13-5: Creating a UIKit view controller
Listing 13-6: Creating the representable view for a UIKit view controller
Listing 13-7: Loading a UIKit view controller from a SwiftUI view
Chapter 14 - Media
Listing 14-1: Creating a Photo picker
Listing 14-2: Embedding the Photos Picker in our interface
Listing 14-3: Hiding controls
Listing 14-4: Defining the model for multiple selection
Listing 14-5: Allowing the user to perform multiple selections
Listing 14-6: Creating the Image Picker Controller to take pictures
Listing 14-7: Defining the interface to take pictures
Listing 14-8: Saving the picture in the Photo Library
Listing 14-9: Sharing the image with other applications
Listing 14-10: Defining a UIView subclass to show the camera's preview video
Listing 14-11: Defining the properties we need to manage the camera
Listing 14-12: Asking for permission to use the camera
Listing 14-13: Initializing the camera
Listing 14-14: Showing the video from the camera on the screen
Listing 14-15: Taking a picture
Listing 14-16: Processing the image
Listing 14-17: Showing the image
Listing 14-18: Taking a picture
Listing 14-19: Preparing the video to be played
Listing 14-20: Playing a video
Listing 14-21: Automatically playing a video
Listing 14-22: Presenting views over the video
Listing 14-23: Building a custom video player
Listing 14-24: Building a custom video player
Listing 14-25: Showing a video
Listing 14-26: Preparing the video player
Listing 14-27: Playing and pausing the video
Listing 14-28: Executing an asynchronous method to detect the end of the video
Listing 14-29: Playing a list of videos
Listing 14-30: Showing a color picker
Chapter 15 - iCloud
Listing 15-1: Storing a value in iCloud
Listing 15-2: Defining the interface to store and read values from iCloud
Listing 15-3: Storing multiple values in iCloud
Listing 15-4: Reading multiple values from iCloud
Listing 15-5: Saving multiple values in iCloud
Listing 15-6: Creating the document
Listing 15-7: Initializing the model required to store a document in iCloud
Listing 15-8: Processing query results
Listing 15-9: Updating the document
Listing 15-10: Defining the main interface
Listing 15-11: Editing the document
Listing 15-12: Working with multiple documents
Listing 15-13: Processing the list of files in the container
Listing 15-14: Updating the container
Listing 15-15: Adding and removing documents from the container
Listing 15-16: Opening, saving, and closing a document
Listing 15-17: Listing the documents available in the container
Listing 15-18: Creating new documents
Listing 15-19: Displaying the document's content
Listing 15-20: Preparing the models for CloudKit
Listing 15-21: Creating the container
Listing 15-22: Showing the list of books
Listing 15-23: Adding books
Chapter 16 - Internationalization
Listing 16-1: Testing String Catalogs
Listing 16-2: Selecting the language for the previews
Listing 16-3: Including comments for the translator
Listing 16-4: Localizing strings
Listing 16-5: Localizing values
Listing 16-6: Specifying singular and plural versions of the text
Chapter 17 - App Store
There are no Examples in this Chapter
TABLE OF CONTENTS
EXAMPLES
LINKS
RESOURCES
FIGURES
Select Country
USA
UK
Deutschland
La France
España
Italia
Nederlands
日本
Brasil
Canada
Mexico
Australia
Paperback
$ 36.95
BUY NOW
Kindle
$ 9.99
BUY NOW
Apple Books
$ 9.99
BUY NOW
Google Books
$ 9.99
BUY NOW
Information
6th Edition
February 2026
ISBN: 978-1-0699942-0-2