iOS Development with SwiftUI
eBook - ePub

iOS Development with SwiftUI

Acquire the Knowledge and Skills to Create iOS Applications Using SwiftUI, Xcode 13, and UIKit

  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

iOS Development with SwiftUI

Acquire the Knowledge and Skills to Create iOS Applications Using SwiftUI, Xcode 13, and UIKit

About this book

Learn iOS Programming Using SwiftUI Framework and Xcode

Key Features
? Demonstrates numerous examples using the SwiftUI concepts.
? A step-by-step walkthrough of the lifecycle of an Xcode 13 project.
? Access to SwiftUI development challenges and expert solutions.

Description
'iOS Development with SwiftUI' focuses on teaching and practicing the use of SwiftUI for developing iOS applications that leverage the latest iOS features.To begin, the book covers the fundamentals of SwiftUI and its core functionalities and how to write UI without having to worry much about it. It explains the fundamental Swift syntax, data types, control statements, functions, classes, and structures, as well as methods, protocols, and closures. The book covers expert tips for adding animations with a single line of code, as well as some SwiftUI transitions. Then, through a dissection of an iOS application, it teaches how to create APIs and implement API calls. It also covers widgets, App Clip development, web banner creation, and how the app communicates with the App Clip.The book will help demonstrate how to integrate XCTest into your application for both UI and unit testing and how to write your test case and prepare the application for general use.At the end of the book, you will be able to write an iOS application in SwiftUI and gain some experience to call API or web services using combine.

What you will learn
? Learn to use the feature 'Combine' in the application and call various APIs.
? Understand data flow and stacks, including VStack, HStack, and ZStack.
? Understand and practice how to share the data between the app and extensions.
? Work with the latest iOS features such as App Clip and Widgets.
? Become well versed with Xcode 13 and UIKit while using it with SwiftUI.

Who this book is for
This book caters to SwiftUI developers, iOS developers, and students who want to build good proficiency in the entire process of iOS application development. Knowing basic programming concepts would be good, although not mandatory.

Table of Contents
1. What is SwiftUI
2. Basics of Swift
3. Anatomy of the Basics of SwiftUI Projects
4. Introduction to SwiftUI Basic Controls and User Input
5. State Properties, Observable, Environment Objects, and Combine Framework
6. Stacks of Views Using VStack, HStack, And ZStack
7. Work with Lists and Navigation.
8. SwiftUI with UIKit
9. UIKit with SwiftUI
10. UI Logic of the MVVM Architecture and Networking
11. Drawing in SwiftUI
12. Animations and Transitions in SwiftUI
13. App Clip
14. Widgets

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access iOS Development with SwiftUI by Mukesh Sharma in PDF and/or ePUB format, as well as other popular books in Computer Science & Content Management Systems. We have over one million books available in our catalogue for you to explore.

CHAPTER 1

What is SwiftUI?

Introduction

In this chapter, we will give you a detailed introduction to Apple’s newest app development framework SwiftUI, after a few general words about SwiftUI, will review its architecture.
WWDC is always a source of exciting stuff for developers; everyone waits with bated breath to see what new tech is being introduced by Apple. The most recent pioneering piece of tech released by Apple was in 2014 when Apple released Swift in addition to Apple’s currently used programming language, Objective-C. Since its release, Swift has updated and evolved, eventually becoming one of today’s most beloved and powerful programming languages.
SwiftUI was announced by Apple at WWDC19 and is described as “SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift” and that’s true with SwiftUI; it’s surprisingly simple to build apps just like you imagine them to look.

Structure

This chapter covers the details of SwiftUI:
  • Introduction to SwiftUI
  • The SwiftUI architecture
  • Opaque types
  • SwiftUI for all Apple products

Objective

The objective of this chapter is to explain SwiftUI, SwiftUI architecture, and technical requirements to run the SwiftUI on macOS. For this book, our focus is on developing iOS applications for the iPhone.
SwiftUI follows a declarative syntax approach, meaning that we depict in code how our interface should look:
Figure 1.1: SwiftUI example with preview

Technical requirements for running SwiftUI

SwiftUI shipped with Xcode 11, which you can download for free from the Mac App Store. Note that SwiftUI is only compatible with running at least macOS Catalina and BigSur or later versions.
When you start creating your project with Xcode 13, you have to select an alternative to storyboard, select the SwiftUI from the dropdown, as seen in the following screenshot:
Figure 1.2: Showing selection option for SwiftUI
This approach to app creation is a true cross-Apple platform and, along with the Catalyst launch, with just a few taps, the iPadOS app is now becoming a true native macOS app, a choice that just wasn’t possible with UIKit.

Introduction to SwiftUI

The SwiftUI framework is quite different from Cocoa. It operates on a programming paradigm that is completely unlike Cocoa. In SwiftUI, there is no storyboard, no nibs, and no outlets. There is no UIViewController, not even a UIView. Text is a struct, and View is just a protocol. A SwiftUI View is extremely lightweight.

Declarative

The declarative syntax is a paradigm of programming that allows you to write more formal and procedural code. The declarative syntax is a way of describing the code you want to write, without worrying about how it’s going to be implemented. Due to SwiftUI’s declarative nature of programming, it changes the paradigm of UI development by revealingly reducing lines of code.
With iOS 13, developers were using UIKit with an imperative technique of UI development. It means that a developer needs to handle the events, UI transition, or maintain states by writing additional lines of code every single time an event should be reflected in the UI. With this technique, apps become more complicated and less readable.
Imperative syntax:
let labelText = UILabel(frame: CGRect(x:0, y:0, width:120, height:120))
labelText.text = “Understanding SwiftUI”
labelText.textColor = UIColor.red
labelText.backgroundColor = UIColor.green
labelText.font = UIFont(name: “Consolas”, size: 26)
self.view.addSubview(labelText)
Declarative Syntax (SwiftUI code):
Text(“Understanding SwiftUI”)
.foregroundColor(.blue)
.background(Color.red)
.font(.largeTitle)
In the preceding code, we see two syntax structures of codes for a similar output. One is imperative nature, and the other is a declarative SwiftUI approach with not so much code but rather more comprehensible what is the issue with the imperative methodology is the developer need to assemble the code, over and over, to check the yield of the coding But in SwiftUI, revelatory user can see the coding yield promptly on the preview.
Output:
Figure 1.3: Output of declarative syntax
With declarative methodology, Apple permits the developer to declare all states for the view at once, no longer needing to write the code for managing the states.
SwiftUI completed this task for the developer to declare rules at the very beginning. The only task left for the developers is to shape the showcase model and refresh.SwiftUI will refresh the UI.
When we used storyboards to make a UI, we got a huge XML document with complicated code that was hard to read. Lately, this XML document has been converted to machine code, and now no more complicated XML in SwiftUI.

Automatic

SwiftUI has no extensive needs for Interface Builder; Canvas, a responsive interface editor, replaced it. When writing code, the visual part in Canvas is automatically generated. When we use SwiftUI previews during development, you can quickly create more flexible and maintainable apps. It allows you to manage themes easily. Developers can easily add dark mode to their apps and set it as the default theme, and users can easily equip dark mode.
It offers a Live Preview. This is a very opportune and reformer way to see the results of code execution in real-time without having to build.SwiftUI preview and also shows our designs in multiple screen sizes at the same time. This speeds up development.

The SwiftUI architecture

The Swift language is an open source, but SwiftUI is not open source and overseen by Apple. When you’ve taken in the nuts and bolts of SwiftUI, you’v...

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Dedication Page
  5. About the Author
  6. About the Reviewer
  7. Acknowledgements
  8. Preface
  9. Errata
  10. Table of Contents
  11. 1. What is SwiftUI?
  12. 2. Basic of Swift
  13. 3. Anatomy of a SwiftUI projects
  14. 4. Introduction to SwiftUI Basic Controls and User Input
  15. 5. State Properties, Observable, Environment Objects, and Combine Framework
  16. 6. Stacks of Views Using VStack, HStack, And ZStack
  17. 7. List and Navigation
  18. 8. SwiftUI in UIKit
  19. 9. UIKit in SwiftUI
  20. 10. Animation and Transitions
  21. 11. Drawing in SwiftUI
  22. 12. MVVM and Networking Using Combine
  23. 13. App Clip
  24. 14. Widgets
  25. Index