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
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mastering iOS 14 Programming
Mastering iOS 14 Programming

Mastering iOS 14 Programming: Build professional-grade iOS 14 applications with Swift 5.3 and Xcode 12.4 , Fourth Edition

Arrow left icon
Profile Icon Mario Eguiluz Alebicto Profile Icon Chris Barker Profile Icon Donny Wals
Arrow right icon
€28.99 €32.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7 (15 Ratings)
eBook Mar 2021 558 pages 4th Edition
eBook
€28.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Mario Eguiluz Alebicto Profile Icon Chris Barker Profile Icon Donny Wals
Arrow right icon
€28.99 €32.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7 (15 Ratings)
eBook Mar 2021 558 pages 4th Edition
eBook
€28.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€28.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering iOS 14 Programming

Chapter 2: Working with Dark Mode

We all love it…well most of us do anyway, and those who do have been asking for it for a while now too. Apple first took the plunge into Dark Mode with macOS Mojave back in 2018, not only changing the way users interacted with the OS but also paving the way for developers to build native dark-themed apps for the first time.

Dark mode for iPhone wasn't announced until WWDC 2019, but we all knew it was coming, and with everything that AppKit had offered, we knew we were in for a treat with what UIKit would have to offer.

In this chapter, we'll cover everything you need to know to get up and running with dark mode in iOS and iPadOS; everything from taking an existing app and making the necessary adjustments to support dark mode, to all the little hidden extras that we can add in when building our app to ensure we give the user the best possible experience. We'll also touch on best practices too – taking note of the little things we can do that allow Dark Mode in UIKit to make our lives so much easier from the start.

The following topics will be covered in this chapter:

  • What is Dark Mode?
  • Working with views in Dark Mode
  • Working with assets
  • Further exploring Dark Mode

Technical requirements

For this chapter, you'll need to download Xcode version 11.4 or above from Apple's App Store.

You'll also need to be running the latest version of macOS (Catalina or above). Simply search for Xcode in the App Store and select and download the latest version. Launch Xcode and follow any additional installation instructions that your system may prompt you with. Once Xcode has fully launched, you're ready to go.

Download the sample code from the following GitHub link: https://github.com/PacktPublishing/Mastering-iOS-14-Programming-4th-Edition.

What is Dark Mode?

In this section, we'll start by taking a look at what exactly Dark Mode is, how we can use it, and what it can do not only for the end user but also for developers. We'll cover everything from enabling it on our devices to using environment overrides in Xcode and developer options in the simulator.

Understanding why we would need Dark Mode

As I covered in the introduction of this chapter, most of us have been craving dark mode in iOS for a very long time now. Us developers got our Xcode fix back in 2018 – but one of the burning questions I've been asked many times (especially in the past 12 months) is…why?

It could be down to something as simple as the time of the day. Satellite navigation systems have been doing it in our cars for years – as soon as the sun goes down, our system switches, and a more relaxing, subtle version of our road home pops up on our screen – so why not do that for our apps?

Well, it turns out that some apps have already been doing that for a while (to a degree), while not necessarily offering an automatic nocturnal mode. The Twitter app for iOS offered a "dark mode" option long before the WWDC 19 announcement.

Let's stop for a moment and think about the logic behind such a control, along with everything you'd need to change to achieve this. I'm sure a company as big as Twitter has written their own internal framework to handle this, but under the hood, it's basically going look a lot like the following:

var isDarkMode = false
var profileLabel: UILabel? {
    didSet {
        profileLabel?.textColor = isDarkMode ? .white : .black
    }
}
var profileBackground: UILabel? {
    didSet {
        profileBackground?.textColor = isDarkMode ? .black : .white
    }
}

Everything will have to be taken into consideration, from the text color to the drop shadows that you might have decorating your UIButton or UIViews.

The background is a massive change to consider too. One common pattern that a lot of iOS developers follow is to quite simply develop a brand-new app on top of a white canvas; from here, we don't need to worry about controlling the background color or keeping track of it with an IBOutlet – it's simply the tablecloth for the rest of our app to sit on.

With implementing a dark mode feature, everything needs to be changed – even asset images that sit proudly on one style of background could be lost in another. Let's take a look at some of the developer features that come bundled with Xcode when implementing Dark Mode.

Core developer concepts of Dark Mode

Let's start by taking a look at how we go about developing with Dark Mode by switching to it on our device. If you've not already done this, you can simply toggle it by going to Settings | Display & Brightness, and you should be presented with the following screen:

Figure 2.1 – Display and brightness

Figure 2.1 – Display and brightness

You'll also notice the Automatic toggle option too, giving us the ability to use either Sunset to Sunrise or a custom schedule, which will automatically switch between light and dark appearance (just like our sat nav).

Now that we've got that covered, let's take a look at some options given to developers in the iOS simulator. Let's start by taking the following steps:

  1. Open up Xcode.
  2. Launch the simulator (Xcode | Open Developer Tool | Simulator).

    In a slightly different location than the end user's version of iOS, you'll find the dark toggle under the developer settings (Settings | Developer | Dark Appearance):

Figure 2.2 – Dark mode developer settings

Figure 2.2 – Dark mode developer settings

Rather than a fancy interface like we saw earlier, we're presented with just the standard toggle. Let's take a look now at what we can do as developers with Dark Mode.

Dark mode from inside Xcode

Now that we've taken a look at how iOS handles switching to dark mode, let's have a look at how we, the developer, can do the same in Xcode.

Out of the box, all new projects building against the iOS 13 SDK will automatically support dark mode; however, building against any earlier SDKs won't.

This helps out a little as your existing app may not have all the necessary tweaks to support dark mode yet and you don't want to release an update to find you have broken your app for those now running dark mode.

However, if you update your project to the iOS 13 SDK, then you could potentially run into this problem, but don't worry, we'll cover getting your existing app ready for dark mode later, in the Migrating existing apps to Dark Mode section in this chapter.

Let's start by having a look at storyboards – we all love them (or hate them) but the one thing they have done over the years is present themselves on a whiter-than-white canvas.

Let's get started:

  1. Launch Xcode and create a new Single View - Storyboard project.
  2. Call this anything you want (I'll call mine Chapter 2 - Dark Mode).

    You can either follow along throughout this chapter or download the sample code from GitHub.

Once created, click on Main.Storyboard and you should be presented with the following:

Figure 2.3 – Xcode interface style

Figure 2.3 – Xcode interface style

I've highlighted in the preceding screenshot our area of interest – here, we have a preview toggle for both light and dark appearances from within the storyboard, so at a quick glance, we can see what the objects we've added to our canvas look like without the need to launch the simulator.

Now, this won't always help us as some of our UILabels or UIButtons could be decorated programmatically. However, it's a great start and will most definitely come in useful during the development cycle of any app.

Let's take a look at our labels in action. Here, we've added a UILabel straight out of the box. Light Appearance is selected, and the label looks just how we are used to seeing things at this stage:

Figure 2.4 – Main storyboard

Figure 2.4 – Main storyboard

Now, let's switch the toggle to Dark Appearance and see what happens:

Figure 2.5 – Main storyboard – dark mode

Figure 2.5 – Main storyboard – dark mode

As if by magic, our canvas enters dark mode, and the color of our UILabel is automatically adjusted. We can see straight away, without the need to compile or run the app on a device or in the simulator, how it will look with each interface style.

I guess the million-dollar question is how did iOS know to switch the color of the UILabel's font? Good question, and we'll cover that in more detail in the Working with views and Dark Mode section later in this chapter.

However, as I mentioned earlier, there are going to be occasions where you'll need to test your app in the simulator. Labels and views will not always be static and could be generated dynamically – this is where environment overrides come in.

We'll start by launching our app in the simulator. Once successfully launched, you should see the following highlighted option available in Xcode:

Figure 2.6 – Environment Overrides

Figure 2.6 – Environment Overrides

Click on this icon and you'll be presented with the Environment Overrides popup. Here, you'll have the option to toggle the Interface Style overrides, which in turn will allow you to choose between light and dark appearance.

If you flick the toggle and switch between each option, you'll see your app in the simulator automatically update without the need to close your app, change the settings, and re-launch. Very nice indeed – thanks, Xcode!

One last little thing to point out before we move on: we mentioned previously that existing apps built with previous iOS SDKs won't be affected by dark mode, but should you choose to update your app to the iOS 13 SDK, you may run into a couple of issues.

Tight deadlines and urgent bug fixes might not necessarily give you the chance to adopt dark mode in your app, so Xcode gives you the option to force light appearance regardless of the user's preference.

In Info.plist (or the Info tab under our project settings), add the following key with the value Light:

UIUserInterfaceStyle
Figure 2.7 – Info.plist – User Interface Style

Figure 2.7 – Info.plist – User Interface Style

You'll now see that even with the environment overrides, you won't be able to switch to dark mode.

In this section, we got up and running with Dark Mode in iOS and, more importantly, Xcode, and learned about the little things that Xcode does to get us ready for developing our apps in both light and dark appearance. In the next section, we'll begin to look at how Xcode handles views and introduce ourselves to semantic "dynamic" colors.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Explore the world of iOS app development through practical examples
  • Understand core iOS programming concepts such as Core Data, networking, and the Combine framework
  • Extend your iOS apps by adding augmented reality and machine learning capabilities, widgets, App Clips, Dark Mode, and animations

Description

Mastering iOS 14 development isn’t a straightforward task, but this book can help you do just that. With the help of Swift 5.3, you’ll not only learn how to program for iOS 14 but also be able to write efficient, readable, and maintainable Swift code that reflects industry best practices. This updated fourth edition of the iOS 14 book will help you to build apps and get to grips with real-world app development flow. You’ll find detailed background information and practical examples that will help you get hands-on with using iOS 14's new features. The book also contains examples that highlight the language changes in Swift 5.3. As you advance through the chapters, you'll see how to apply Dark Mode to your app, understand lists and tables, and use animations effectively. You’ll then create your code using generics, protocols, and extensions and focus on using Core Data, before progressing to perform network calls and update your storage and UI with the help of sample projects. Toward the end, you'll make your apps smarter using machine learning, streamline the flow of your code with the Combine framework, and amaze users by using Vision framework and ARKit 4.0 features. By the end of this iOS development book, you’ll be able to build apps that harness advanced techniques and make the best use of iOS 14’s features.

Who is this book for?

This book is for developers with some experience in iOS programming who want to enhance their application development skills by unlocking the full potential of the latest iOS version with Swift.

What you will learn

  • Build a professional iOS application using Xcode 12.4 and Swift 5.3
  • Create impressive new widgets for your apps with iOS 14
  • Extend the audience of your app by creating an App Clip
  • Improve the flow of your code with the Combine framework
  • Enhance your app by using Core Location
  • Integrate Core Data to persist information in your app
  • Train and use machine learning models with Core ML
  • Create engaging augmented reality experiences with ARKit 4 and the Vision framework

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 19, 2021
Length: 558 pages
Edition : 4th
Language : English
ISBN-13 : 9781838822606
Vendor :
Apple
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Mar 19, 2021
Length: 558 pages
Edition : 4th
Language : English
ISBN-13 : 9781838822606
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

Frequently bought together


Stars icon
Total 115.97
SwiftUI Cookbook
€31.99
Swift Cookbook
€41.99
Mastering iOS 14 Programming
€41.99
Total 115.97 Stars icon

Table of Contents

21 Chapters
Chapter 1: What's New in iOS 14? Chevron down icon Chevron up icon
Chapter 2: Working with Dark Mode Chevron down icon Chevron up icon
Chapter 3: Using Lists and Tables Chevron down icon Chevron up icon
Chapter 4: Creating a Detail Page Chevron down icon Chevron up icon
Chapter 5: Immersing Your Users with Animation Chevron down icon Chevron up icon
Chapter 6: Understanding the Swift Type System Chevron down icon Chevron up icon
Chapter 7: Flexible Code with Protocols, Generics, and Extensions Chevron down icon Chevron up icon
Chapter 8: Adding Core Data to Your App Chevron down icon Chevron up icon
Chapter 9: Fetching and Displaying Data from the Network Chevron down icon Chevron up icon
Chapter 10: Making Smarter Apps with Core ML Chevron down icon Chevron up icon
Chapter 11: Adding Media to Your App Chevron down icon Chevron up icon
Chapter 12: Improving Apps with Location Services Chevron down icon Chevron up icon
Chapter 13: Working with the Combine Framework Chevron down icon Chevron up icon
Chapter 14: Creating an App Clip for Your App Chevron down icon Chevron up icon
Chapter 15: Recognition with Vision Framework Chevron down icon Chevron up icon
Chapter 16: Creating Your First Widget Chevron down icon Chevron up icon
Chapter 17: Using Augmented Reality Chevron down icon Chevron up icon
Chapter 18: Creating a macOS app with Catalyst Chevron down icon Chevron up icon
Chapter 19: Ensuring App Quality with Tests Chevron down icon Chevron up icon
Chapter 20: Submitting Your App to the App Store Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7
(15 Ratings)
5 star 93.3%
4 star 0%
3 star 0%
2 star 0%
1 star 6.7%
Filter icon Filter
Top Reviews

Filter reviews by




Balazs A Mar 29, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It's the deepest book on iOS development I have ever purchased on Amazon.
Amazon Verified review Amazon
zoha Apr 12, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you're looking to make an iOS app, and you want to learn how to do it properly this is the book with the perfect foundation. It starts with an intro on what's new in IOS 14 and goes over all the advanced and latest concepts like the widgetkit, ARkit, Machine learning, etc in a step-by-step detailed manner. it really spoke to me in a way that was easy to understand.
Amazon Verified review Amazon
Jean Meyer (iOS Dev & Crypto Guru) Mar 30, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I really believed I knew how to dev on iOS... Well, I didn't. This book isn't reinventing the wheel. It explains in detail every iOS concept. Perfect fit both for beginners and pros as it will take your hand step by step from the "Idea stage" to "Publishing your app to the AppStore"... Congrats to the authors. I would have maybe appreciated a chapter about iOS & Blockchain but I guess that will come in the next edition ;)
Amazon Verified review Amazon
jared cassoutt Mar 22, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I love this book! Not only does it cover many of the topics that are necessary to be an iOS developer, but it also includes many fun topics such as CoreML, ARKit 4, and the Vision Framework. I would highly recommend this book to any current mobile developers or individuals looking to become an iOS developer!!!
Amazon Verified review Amazon
Gurleen Kaur May 21, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Most of the concepts are explained very well and it is really interesting to keep reading.As a iOS developer, who is getting back into development it’s really great to revise the concept and everything new in the update.I really love the book and highly recommend it
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.