Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Mastering iOS 18 Development
Mastering iOS 18 Development

Mastering iOS 18 Development: Take your iOS development experience to the next level with iOS, Xcode, Swift, and SwiftUI

Arrow left icon
Profile Icon Avi Tsadok
Arrow right icon
€18.99 per month
Paperback Nov 2024 418 pages 1st Edition
eBook
€8.99 €25.99
Paperback
€31.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Avi Tsadok
Arrow right icon
€18.99 per month
Paperback Nov 2024 418 pages 1st Edition
eBook
€8.99 €25.99
Paperback
€31.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €25.99
Paperback
€31.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Mastering iOS 18 Development

What’s New in iOS 18

Apple introduced iOS 18 in WWDC 2024 as part of its annual developer’s conference, alongside macOS, tvOS, iPadOS, watchOS, and visionOS.

Utilizing our app’s latest features and capabilities in each major OS release gives us a competitive advantage. Here are the reasons why Apple chose to improve particular domains in the SDK – market research or technology trends are good enough reasons to adopt new technologies.

However, to understand iOS 18 improvements, we first must understand the background for this version – that’s one of this chapter’s goals.

In this chapter, we will cover the following topics:

  • Understanding iOS 18 background
  • Exploring Swift Testing
  • Learning about the new Swift Data improvements
  • Trying the new zoom transition
  • Adding a floating tab bar to our iPad apps
  • Having more control over scroll views in SwiftUI
  • Changing the text rendering behavior
  • Positioning...

Technical requirements

For this chapter, it’s essential to download Xcode version 16.0 or higher from the App Store.

Ensure that you’re operating on the most recent version of macOS (Ventura or newer). Just search for Xcode in the App Store, choose the latest version, and proceed with the download. Open Xcode and complete any further setup instructions that appear. After Xcode is completely up and running, you can begin.

This chapter includes many code examples, and can be found in the following GitHub repository:

https://github.com/PacktPublishing/Mastering-iOS-18-Development/tree/main/Chapter%201

Understanding iOS 18 background

Releasing a major iOS version is always a big deal, even if it’s the 18th already. Let’s try to analyze the iOS SDK before iOS 18:

  • SwiftUI is becoming more mature and capable. However, some features, such as complex animations or transitions, gesture handling, navigation, and drawing, remain challenging to implement using SwiftUI.
  • Core Data is the go-to framework for most iOS developers as a solution for storing data persistently.
  • While XCTest is considered a robust and convenient testing framework, it lacks features that are commonly available on other platforms, such as parameterized testing and better testing organization.
  • WidgetKit’s popularity proves that the ability to show information at a glance is crucial in today’s world.

No one can argue that this list is important. However, one critical topic that Apple didn’t focus on until WWDC 2024 is artificial intelligence.

The rise of...

Introducing Swift Testing

Swift Testing is a new framework with a new and refreshing approach to testing. Swift Testing contains modern features such as macros, which work with structs instead of classes and can tag tests and test suites.

Swift Testing is supposed to replace XCTest, which was introduced in 2013 as part of Xcode 5. XCTest belongs to older times when Objective-C was the dominant language. However, Swift took over, and Apple understood that iOS developers needed a modern testing framework.

Here’s a simple test function:

@Test("Test view model increment function", .enabled(if: AppSettings.CanDecrement), .tags(.critical))
func testViewModelIncrement() async throws {
//         preparation
        let viewmodel = CounterViewModel()
        viewmodel.count = 5
//        execution
 ...

Introducing Swift Data Improvements

Swift Data was introduced in WWDC 2023 as part of iOS 17, and its goal was to replace the old but popular Core Data framework.

Swift Data provides a modern API based on Swift, which can help reduce friction when working with persistent stores. One of the trends we see in Apple development tools is moving away from GUI to code-based tools. A good example is SwiftUI – even though it is possible to drag and drop components to build a user interface, the primary way to do this is in code. The same goes for App Intents and Swift Package Managers. The data layer goes through the same concept – in Swift Data, we don’t have any data model editor, so we build our data model using only code.

For example, here’s how to create a data model for a Book entity:

@Model
class Book {
    var author: String
    var title: String
    var publishedDate: Date
}

At first...

Introducing zoom transition

This is a small improvement, but it may indicate an interesting direction Apple is taking with SwiftUI. In general, UIKit’s transitioning capabilities are very robust and provide us with the flexibility to create any transition we want. Even before that, from the beginning, UIKit had some nice built-in transitions we could use to make our navigation more appealing.

In iOS 18, Apple added a new transition that allows us to navigate to a new view using a zoom animation.

Let’s create an album grid that, when tapping on the album, transitions to a full album screen with a zoom animation:

    @Namespace() var namespace
    var body: some View {
        NavigationStack {
            ScrollView {
                LazyVGrid...

Adding a floating tab bar

iPad is not the focus of this book. This is not because iPadOS is unimportant but because most, if not all, of the topics we discuss here are also suitable for iPadOS.

However, there are special features that are relevant to iPadOS that are worth mentioning. One of them is the float tab bar.

The tab bar has existed in iOS since its very beginning. It allows users to navigate between different sections of an app. In both iOS and iPadOS, the tab is located at the bottom of the screen. While it looks perfectly fine on small devices, a tab bar on big screens seems stretched and doesn’t use the large space.

One solution for handling navigation in a iPadOS is to implement a sidebar – a view on the side that displays the different sections of the app.

In iPadOS 18, the position of the sidebar changed, and it is now located at the top of the screen, floating over the app content. Not only that; the user can also transition between a tab bar...

Having more control over scroll views

Controlling and observing scroll view behavior was part of the reason why UIKit developers hadn’t moved to SwiftUI yet.

Scroll views are crucial in mobile apps, not just because of the small screen, which often requires the user to scroll for more content, but also because they help reuse visible content to minimize memory usage or adjust our UI based on scroll position.

However, why is handling scroll views in SwiftUI more complex than in UIKit? We can think of two reasons:

  1. SwiftUI is relatively new: SwiftUI is still considered to be a new framework. Think how much time it took for UIKit to become a mature framework. Obviously, we can achieve this in several years and 17 years of development.
  2. Flexibility: Due to the imperative approach, UIKit gives us direct control over views. This means that we can adjust particular view parameters based on the scroll state. SwiftUI’s declarative nature sometimes makes achieving...

Changing the text rendering behavior

Handling texts on screen was also a very mature area where UIKit provided great frameworks such as TextKit. We could manipulate texts and create almost any effect that we wanted.

In iOS 18, Apple introduced TextRenderer, a protocol that can help us change the default behavior of our texts in SwiftUI.

Let’s say that we want a title with a different opacity for each line and even rotate the lines a bit. This creates a nice effect for the titles in our app. So, let’s see how to do that in SwiftUI:

struct CustomTextRenderer: TextRenderer {
    func draw(layout: Text.Layout, in ctx: inout
     GraphicsContext) {
        for (index, line) in layout.enumerated() {
            ctx.opacity = Double(index + 1) * 0.1
            ctx...

Positioning sub-views from another view

What does it mean to position sub-views from another view? While this description sounds weird and unclear, it is a nice addition to SwiftUI that can help us provide more dynamic and reusable content.

To understand what it means, let’s take the following code as an example:

struct NewsView: View {
    var body: some View {
        Text("Major Breakthrough in Renewable Energy: New Solar Panel Technology Promises 30% Efficiency Increase")
        Text("lobal Markets React to Sudden Interest Rate Hike: Stocks Tumble Across the Board")
        Text("Historic Peace Agreement Reached: Leaders Sign Pact to End Decades-Long Conflict")
        Text("Innovative AI Tool Revolutionizes Healthcare: Doctors Embrace Machine Learning...

Entering the AI revolution

AI and machine learning are not new areas for Apple and the iOS platform. Apple uses AI to adjust photos taken, suggest apps to users according to their usage, optimize battery charging, and many more.

For developers, Apple provides the CoreML framework and tools such as Create ML to help users train and create their own machine learning models.

However, the rising popularity of services such as ChatGPT and Gemini proved that CoreML is insufficient, and that Apple needs to integrate AI deeper into the system.

So, what did Apple prepare for us, the developers, regarding AI in iOS 18?

Apple integrated AI into iOS 18 by letting iOS understand what’s happening in the system and helping the user perform common tasks using natural language understanding, similar to ChatGPT.

For example, let’s say we’re working on a word-processing app and created an App Intent that allows the user to add an image to a document.

Until iOS 18...

Summary

There’s no other way of looking at iOS 18 than as an exciting one. The addition of Apple Intelligence is only part of the story – Apple took care of many system and SDK aspects such as testing, persistent data, UI, and more.

In this chapter, we explored the basics of the new Swift Testing framework, learned about Swift Data improvements, and discussed enhancements in SwiftUI such as zoom transition, floating tab bar, scroll views, and text rendering. We even scratched the surface of Apple Intelligence and tried to understand how it is integrated with App Intents. By now, you should be familiar with the most exciting and new topics in iOS 18.

A few code examples are just not enough. We are developers, and we need more! So, let’s jump straight into SwiftData and explore Apple’s new persistent data framework in the next chapter.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Stay up to date with the latest changes and improvements in iOS SDK and Swift programming language
  • Learn how you can improve user experience by focusing on customizing components and animations
  • Get to grips with advanced topics such as SwiftData and high-efficiency applications through an in-depth discussion
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Embark on a comprehensive iOS 18 development journey with Avi Tsadok, a veteran iOS developer and author of 4 books and over 40 tutorials and articles. A recognized public speaker, Avi has a knack for demystifying complex concepts and brings unparalleled expertise to the forefront of iOS 18 development education. This guide focuses on iOS 18 advancements, equipping developers with tools to maximize its potential. This book covers essential topics for seasoned developers, including Swift, SwiftUI, Xcode foundations, and the latest iOS SDK updates. You’ll get to grips with optimizing performance and understanding advanced architectural paradigms. By implementing the newest iOS updates, you’ll also explore intricate animation methods and harness a new framework, SwiftData that replaces Core Data for having persistent storage. The book builds your proficiency in advanced networking with URLSession and shows you how to conjure stunning visuals and adopt sophisticated testing techniques. You'll explore the world of machine learning with Apple’s Core ML diving into built-in frameworks like NLP, vision, and sound analysis to train and integrate your own models into iOS apps. By the end of the book, you'll possess skills to build exceptional apps, excel in advanced roles, and confidently tackle iOS development challenges.

Who is this book for?

If you are an experienced iOS developer looking to enhance your mobile development skills, create exceptional applications, and excel in advanced positions, this book is designed for you. To derive maximum benefit from this book and ensure a strong understanding of the advanced content, it is recommended that you have a solid foundation in Swift, SwiftUI, and Xcode.

What you will learn

  • Develop functional iOS applications on the iOS platform
  • Build intricate custom animations and UI elements
  • Master data handling and persistence in iOS apps
  • Utilize Combine for efficient data management
  • Harness the power of the neural engine through CoreML
  • Explore architectures and streamline programming with Swift Macros
  • Improve engagement by adding Widgets and App Intents

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 08, 2024
Length: 418 pages
Edition : 1st
Language : English
ISBN-13 : 9781835468104
Vendor :
Apple
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Nov 08, 2024
Length: 418 pages
Edition : 1st
Language : English
ISBN-13 : 9781835468104
Vendor :
Apple
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
Banner background image

Table of Contents

19 Chapters
Part 1: Getting Started with iOS 18 Development Chevron down icon Chevron up icon
Chapter 1: What’s New in iOS 18 Chevron down icon Chevron up icon
Chapter 2: Simplifying Our Entities with SwiftData Chevron down icon Chevron up icon
Chapter 3: Understanding SwiftUI Observation Chevron down icon Chevron up icon
Chapter 4: Advanced Navigation with SwiftUI Chevron down icon Chevron up icon
Chapter 5: Enhancing iOS Applications with WidgetKit Chevron down icon Chevron up icon
Chapter 6: SwiftUI Animations and SF Symbols Chevron down icon Chevron up icon
Chapter 7: Improving Feature Exploration with TipKit Chevron down icon Chevron up icon
Chapter 8: Connecting and Fetching Data from the Network Chevron down icon Chevron up icon
Chapter 9: Creating Dynamic Graphs with Swift Charts Chevron down icon Chevron up icon
Part 2: Refine your iOS Development with Advanced Techniques Chevron down icon Chevron up icon
Chapter 10: Swift Macros Chevron down icon Chevron up icon
Chapter 11: Creating Pipelines with Combine Chevron down icon Chevron up icon
Chapter 12: Being Smart with Apple Intelligence and ML Chevron down icon Chevron up icon
Chapter 13: Exposing Your App to Siri with App Intents Chevron down icon Chevron up icon
Chapter 14: Improving the App Quality with Swift Testing Chevron down icon Chevron up icon
Chapter 15: Exploring Architectures for iOS Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.