Ios Development With Swiftui Acquire The Knowledge and Skills To Create Ios Applications Using Swiftui Xcode 13 and Uikit Download
Ios Development With Swiftui Acquire The Knowledge and Skills To Create Ios Applications Using Swiftui Xcode 13 and Uikit Download
https://ebookbell.com/product/ios-development-with-swiftui-
acquire-the-knowledge-and-skills-to-create-ios-applications-
using-swiftui-xcode-13-and-uikit-37568312
Beginning Iphone Development With Swiftui Exploring The Ios Sdk 7th
Edition 7th Wallace Wang
https://ebookbell.com/product/beginning-iphone-development-with-
swiftui-exploring-the-ios-sdk-7th-edition-7th-wallace-wang-50584916
Beginning Iphone Development With Swiftui Exploring The Ios Sdk 6th
Edition Wally Wang
https://ebookbell.com/product/beginning-iphone-development-with-
swiftui-exploring-the-ios-sdk-6th-edition-wally-wang-37244008
https://ebookbell.com/product/ios-15-application-development-for-
beginners-learn-swift-programming-and-build-iphone-apps-with-swiftui-
and-xcode-13-arpit-kulsreshtha-37311976
https://ebookbell.com/product/ios-15-application-development-for-
beginners-learn-swift-programming-and-build-iphone-apps-with-swiftui-
and-xcode-13-kindle-arpit-kulsreshtha-44859382
Mastering Ios 18 Development Take Your Ios Development Experience To
The Next Level With Ios Xcode Swift And Swiftui 1st Edition Avi Tsadok
https://ebookbell.com/product/mastering-ios-18-development-take-your-
ios-development-experience-to-the-next-level-with-ios-xcode-swift-and-
swiftui-1st-edition-avi-tsadok-74428628
Ios 17 App Development For Beginners Get Started With Ios App
Development Using Swift 59 Swiftui And Xcode 15 Arpit Kulsreshtha
https://ebookbell.com/product/ios-17-app-development-for-beginners-
get-started-with-ios-app-development-using-swift-59-swiftui-and-
xcode-15-arpit-kulsreshtha-53883114
https://ebookbell.com/product/ios-development-with-xamarin-cookbook-
dimitris-tavlikos-4984670
https://ebookbell.com/product/ios-development-with-swift-1st-edition-
craig-grummitt-7371420
https://ebookbell.com/product/ios-development-with-xamarin-cookbook-
dimitris-tavlikos-5132540
iOS Development
with SwiftUI
Mukesh Sharma
www.bpbonline.com
FIRST EDITION 2022
ISBN: 978-93-91030-98-8
There are a few people I want to thank for the continued and
ongoing support they have given me during the writing of this
book. First and foremost, I would like to thank my wife and my
son, Laxit, for putting up with me while I was spending many
weekends and evenings on writing—I could have never completed
this book without their support.
Chapter 13 App Clip introduces the App Clip which is really a very
nice and advanced feature.
https://rebrand.ly/cf7ae1
Errata
errata@bpbonline.com
Your support, suggestions and feedbacks are highly appreciated by
the BPB Publications’ Family.
Did you know that BPB offers eBook versions of every book
published, with PDF and ePub files available? You can upgrade to
the eBook version at www.bpbonline.com and as a print book
customer, you are entitled to a discount on the eBook copy. Get
in touch with us at: business@bpbonline.com for more details.
If you come across any illegal copies of our works in any form
on the internet, we would be grateful if you would provide us
with the location address or website name. Please contact us at
business@bpbonline.com with a link to the material.
If there is a topic that you have expertise in, and you are
interested in either writing or contributing to a book, please visit
We have worked with thousands of developers and tech
professionals, just like you, to help them share their insights with
the global tech community. You can make a general application,
apply for a specific hot topic that we are recruiting an author for,
or submit your own idea.
Reviews
Please leave a review. Once you have read and used this book,
why not leave a review on the site that you purchased it from?
Potential readers can then see and use your unbiased opinion to
make purchase decisions. We at BPB can understand what you
think about our products, and our authors can see your feedback
on their book. Thank you!
1. What is SwiftUI?
Introduction
Structure
Objective
Technical requirements for running SwiftUI
Introduction to SwiftUI
Declarative
Automatic
The SwiftUI architecture
Opaque types
Group
AnyView
ViewBuilder
SwiftUI for all Apple products
Conclusion
Questions
2. Basic of Swift
Introduction
Structure
Objectives
Basic Swift syntax
Constant
Variables
Comments
Basic data types
Integers
Floating-point numbers
Booleans
String
Characters
Tuples
Arrays
Retrieving elements from an array
Inserting elements into an array
Modifying elements in an array
Appending elements to an array
Removing elements from an array
Dictionaries
Creating dictionary
Retrieving elements from a dictionary
Modifying an item in a dictionary
Removing an item from a dictionary
Optional type
Working with implicitly unwrapped optionals
Using optional binding
Optional chaining
Unwrapping optionals using “?”
Using the nil coalescing operator
Flow control
if…else statement
Ternary conditional operator
The Switch statement
Looping
for-in loop
while loop
Functions
Understanding input parameters
Returning a value
Class and structures
Reference type (Class):
Value type (Structure):
Creating a class or structure
Properties
Stored properties
Computed properties
Methods
Instance method
Type method
Protocols
Define a protocol
Conforming to a protocol
Closures
Creating a closure
Hello Welcome
Using closures with arrays
Conclusion
Questions
EmptyProjectApp.swift
App states
ContentView.swift
AppDelegate with SwiftUI app
Multi-window support
Assets.xcassets
Preview Assets.xcassets
Conclusion
Questions
GroupBox
DisclosureGroup
OutlineGroup
Alert modifier
Context menu
Conclusion
Questions
Conclusion
Questions
8. SwiftUI in UIKit
Introduction
Structure
Objective
Technical requirements for running SwiftUI
UIHostingController
An UIHostingController example
Adding a hosting controller
Segue action in the view controller
SwiftUIView file
SwiftViewUI.swift
Without segue action
Conclusion
Questions
9. UIKit in SwiftUI
Introduction
Structure
Objective
Technical requirements for running SwiftUI
UIViewRepresentable protocol
An UIViewRepresentable example
UIViewControllerRepresentable
Coordinator
DocumentPickerViewController in SwiftUI
Conclusion
Questions
Asymmetric transitions
Combining transitions
Conclusion
Questions
Structure
Objective
Technical requirements for running SwiftUI
MVVM design pattern
My JSON server
API design
Creating the APIError class
Network layer
Codable
NewsViewModel
View
ProgressView
Conclusion
Questions
14. Widgets
Introduction
Structure
Objectives
Technical requirements for running SwiftUI
An overview of widgets
Widget extension
Widget entry view
Widget timeline entries
Widget provider
Reload policy
Widget sizes
Modifying MyWidget.swift class
Changing widget background
Deep linking
Creating a URL scheme
Changes in the ContentView
Conclusion
Questions
Index
CHAPTER 1
What is SwiftUI?
Introduction
Introduction to SwiftUI
Opaque types
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:
Imperative syntax:
Output:
When SwiftUI sits on top of the application code and creates the
application that displays UI elements, it does not create native
elements from the code.
Starting in Swift 5.1 and iOS 13, a function return type can be
specified as some supertype without stating subtype. The syntax is
the keyword followed by the supertype.
The following code snippets return the Text view (this is valid
because Text conforms to the View protocol):
Other the Text view, you can also return a VStack view (which is
also valid as VStack conforms to the View protocol):
if isText {
RoundedRectangle(cornerRadius: 10)
.fill(Color.orange)
Group
AnyView
ViewBuilder
Group
extension ContentView{
func shapeOrText() -> some View{
Group{
if isText {
RoundedRectangle(cornerRadius: 10)
.fill(Color.orange)
.frame(width: 100, height: 100)
}else
{
Text(“SwiftUI”)
.font(.largeTitle)
}
}
}
}
extension ContentView{
func shapeOrText() -> some View{if isText {
return AnyView(RoundedRectangle(cornerRadius: 10)
.fill(Color.orange)
.frame(width: 100, height: 100))
}else
{
return AnyView(Text(“SwiftUI”)
.font(.largeTitle))
}
}
}
ViewBuilder
extension ContentView{
@ViewBuilder
func shapeOrText() -> some View{
if isText {
RoundedRectangle(cornerRadius: 10)
.fill(Color.orange)
.frame(width: 100, height: 100)
}else
{
Text(“SwiftUI”)
.font(.largeTitle)
}
}
}
Ane othir coloure is the Quhyte coloure, the quhilk next the Asure is
the maist noble coloure that was countit in Armoury in ancien
cronikis, because that it is maist nere the nature of lycht and
claritee; and for the clereness of it, it is signyfyit to the vertu of
puritee, of clenesse, and innocence, and sympilness: And as to that
the Haly Scripture sais, that the clethingis of Jhesu Crist apperit ay
to thame of quhite colour as snaw; and this coloure of quhite
representis the Water, the quhilk efter the Aire is the maist noble
element.
To the Thrid reugle and doctrine of battaill in Listis is this: That the
Prince in na case suld juge bataill to be, bot quhare thare is na prufis
allegit na producit, and that is law commoun and reasonnable
custum; bot he sall suere, be his faith, that his cause can nocht be
prufit in na way bot be his persoun.
The Fyft doctrine is: That for na wordis of hete, and sudane ire of
chaude cole or of chaude mellencoly, na injuriouse langage, thare
suld na Prince thole na consent gage of bataill in listis to pas; for
wordis may be said for hete, or for brethe, or for gude wyne, or othir
wayis in lichtnes, that sone efter he may repent: bot and the wordis
be injurious and dishonourable, crimynouss or defamatouris, and he
perseuere in his outrageous langage, and lykis nocht till amend; bot
stand in his purpos efter that the ire salbe past, ellis the Prince suld
nocht juge bataill to be: ffor gif he dois, he jugis again the Lawis
writtin opynly.
The Sext doctrine is: That because thare is sum men sa hichty
hautayn and orguillous and full of surquedry, that thai haue na traist,
na fyaunce in God na his Sanctis, bot in thair awin propre pyth and
vertu of corps and strenth of membris; na has na will; na thocht on
God to mend thair mysdedis; na to tak counsale at gude men of lyf
and deuocion; na to mak gude ordynaunce for thame self, suppose
the Prince suld the bataill to be tholit to be done to the vtterest: And
tharfore the King suld assigne certane day of bataill and houre to the
Appelloure, and he suld ger schaw him the grete perile in the quhilk
he puttis him in baith of body and of saule, and monyse him, and
exhort him on Goddis behalf, that all before that euer he schape him
for horse, harnais, na othir prouision for the bataill, that first he
schape him to se for a gude Confessour, that be a gude wise clerke,
wele letterit and wele instruct in the faith, and of gude counsale and
conscience, that he may discharge his conscience to, and schrive
him wele, and put his saule first in gude estate, and his gudein
ordinance, as he wald mak his testament to ga to dede, and as wyse
man aw to do: Quhilk gif he dois nocht, the King suld say him, "That
sen he traistit nocht in Goddis help, he suld nocht traist that he war
a gude Cristyn man, and that he suld haue the lesse fauour of him;"
and than suld he ordane him a term within quhilk he suld put him in
gude estate of the saule to Godwart, and syne spere, how thai had
done at thair Confessoure, and sa suld he do to the tothir: And this
is a takyn that a Prince is wyse, and lufis wele God, that begynnis at
him to dispone all his gouernance and dedis.
Fol.
81. b.
HERE SPERIS THE DOCTOURE QUHAT THINGIS EFFERIS TILL ALL GUDE PRINCE
TO DO
Fol.
83. b.
Fol.
84. b.
Item, a Prince or a King suld nocht oure lichtly trow all talis na
sudayn tydingis; ffor mony learis oft tymes flechis lordis with false
talis, and settis thame in wrang and euill purpose. And that is oure
grete perile in princis and grete lordis, to geue sudane credence till
ony mannis tale, quhill he war wele informyt of the suthfastnes: And
he suld be wele and ryply avisit, or that he write to the Pape ony
materis, or till ony strange Princis, for ony lycht mennis counsailis, or
ony small wrechit mannis. And quhen he wrytis, his writtis suld be
wele and statelyke deuisit, and dytit be wise Clerkis, and men of
counsale, and expert in the lawis and purpose lyke, and syne be
notable gude wrytaris as efferis; bathe to the ryaltee of him that
sendis the writtis, and of him that thai wryttis ar send to; and suld
wele auise for quham he wrytis, that thai be worthy persouns, and
alssua for quhat thing he wrytis; that it be nocht a wrechit thing that
he wrytis for; and als that his peticioun be bathe rychtwise and
honourable; ffor quhen Princis prayis for vnworthy persouns, God is
offendit and displesit thareat. And syne the Pape or Princis that he
wryttis till, will hald him for ane vnwise Prince that the lettres send
for sik a persone, and will nocht sa gladly grant him his asking in
tyme to cum. And thus sall the renoun of a Prince pas oure all the
Cristyndome, and geue him lofe and honour that excedis all warldis
richess, throu the quhilk he sal be prisit and redoubtit bathe with fais
and frendis, and haldin for wise Prince; and syne sall he be lufit of
God, and wyn throu that the joy of Paradise.
And suppose I mycht ȝit compile and gader togedir mony Vertues
and properteis that suld be in a Prince, and als mony thingis of
Mysgouernaunce that he suld eschew: Bot in gude faith the Doctour
sais, that he was sa irkit of wryting, that he mycht nocht as now na
mare tak on hand as to put in this Buke of Bataillis; bot and God
geve him lyve dayes, he sais, in his conclusioun of his Buke, he sall
compile a Trety of propereteis of Gude Condiciouns bathe of
Temparale men and of men of Kirk, that sall be gude and
prouffitable for all men, that on lukis bathe langand the gouernaunce
of thair office and digniteis, as may be compylit be the foundement
of Haly Writt, and efter the Lawis writtyn. Bot here he prayis to God
mekely that he send grace and gude gouernaunce to the Prince that
he has compilit this wrytt for, and maid this Buke till, that is to say
King Philip[20] of Fraunce, and geue him grace sa to reule his
realme, and his ryall magestee and estate, that God be payit of him,
and bring him till his euerlestand joye of Paradise at his ending, and
all his frendis and wele willaris. In nomine Patris, et Filii, et Spiritus
Sancti. Amen.
No. II.
HERE BEFORE ENDIS THE BUKE OF BATAILLES, AND HERE EFTER BEGYNNYS
Item, Of the first Pistle fend fra Alexander till Arestotil to ask him
counsale of the Gouernaunce of Perse new conquest; and of the
form of the Epistle, and of his Ansuere.
Item, Of ane othir of thé Ansueris of Aristotle till Alexander; and the
forme of the Epistle send fra Aristotle of his opynion.
PROLOGUS.
till
HERE DECLARIS HE HOW ARISTOTLE RESSAUIT A PISTLE SENT FRA ALEXANDER
him in his grete age, to ask counsale, quhen he had conquest
Perse, Quhethir he suld destroy and sla all the folk of that land,
and peple it with others? because that thay war perilouse to
gouerne, and subtile, and full of mychti maliciouse engyne of
conquest, for the quhilk he dred thair subtile malice.
The quhilkis lettres the Prince ressauit with benignitee, and fulfillit
his counsale vtterly; throu the quhilkis thingis the peple of Perse
gafe sik a luferent till Alexander, that thai lufit him better, and was
mare obeysand till him, na ony othir pepele of ony of his othir
conquestis.
excusand
HERE FOLLOWIS A PISTLE SEND FRA ARISTOTIL TILL ALEXANDER
him for sore elde and waykenes he mycht na mare byde with
him na hald the court; and tharfore he send him a Regement in
wrytt, how and in quhat maner he suld gouerne him ay furth;
the quhilk begynnis in this maner as efter folowis:—
XL.—CAPITULUM.
Fol.
129.
Alexander, faire Sone, ȝit will I that thow witt, that thy subjectis suld
be kepit as thy tresouris, ffor thai ar thy tresoure. For thai may be
comperit till a Lord that has a faire and gude gardyn quhare thare is
grete quantitee of fruyte treis, herbis, and othir gresis, richess, and
nedefull till mannis behufe, the quhilkis ȝerely and contynualy beris
grete plentee of fruytis for mannis sustenaunce quhen thai ar well
grathit, scroubbit, and demaynit, and wele gudit, kepit, sustenit, and
gouernyt at rycht, and suld be wele sene to, and socourit at thair
nedis. And kepit wele in gude reugle of justice and saufit fra injuris
and oppressins, and that thare be bot thou allane gardener upon
thame, and nocht mony maister gardenaris; ffor quhare mony
maister gardeneris ar the gardyn is nocht commounly all prouffitably
gouernyt, the quhilk suld be of gude gouernaunce that stent him
nocht to spill thy treis, na gader thy fruytis, that is to say, thy
subjectis gudis wrangwisely; and sa may thy realme left, and be
wele defendit and conseruit, sa that thou kepe thé nocht to haue
mony dispensaris in thy gardyn, that is thy realme. Ffor quhy, for
couatise and gredynes of thy fruytis, thar may enter corrupcioun in
thy gardyn, and syne apon thyself, quhen ilk ane pressis oure otheris
to be masteris of thi gudis, and of thy counsaile, and thi
gouernaunce. Bot thare is mony that will hecht and say thai sall do
wele, and quhen thai mount in gouernaunce thai do all othir wayis.
And sum corrumpis be giftis and hechtis Princis Counsailouris, and
peruertis all gude gouernaunce throu thair gredyness of gudis,
gevand giftis to Lordis of the Counsale for to maneteine thame lang
in thaire officis and in thaire malicis. And traist wele, Alexander, that
thy Peple and thy Barouns, thy Bacheleris and thy Commons ar the
stuf and the multiplicacioun and furnyssing of thy realme, and be
thame mon thou be crownyt, and thy croun vphaldyn and
mayntenyt, and be thai nocht throu thé manetenyt and sustenyt in
thair rychtis and richess, thai will nocht lufe thé, na honoure thé, na
tho court, na help to sustene thyne estate; ffor bot gyf thou mak
thaim cause to be fyablez and traist to thé, and thy worschip and
prouffit, and to hald lufe and lautee betuix thé and thy peple, thou
fall neuer be seker na seure a day in thy realme. And will thou
vmbethink thé wele of all that I haue said, and gouerne thé efter my
deuise and counsale beforesaid, thou sal be haldyn as wyse and
worthy King, and doubtit and lufit of thy peple, and of all otheris:
And thou sall cum aboue of all thyne vndertakingis and desyris:
Quhilkis gif thou faillis to do, thou sall se that thare sall cum
greuouse mischeif and mysfortune, bathe upon thé and thy realme,
and thy gouernaunce, and it sall nocht be in thy powar to sett
remede, na thou can nocht, na may nocht estymy the paynis that
suld be injunct to thé tharfore. Bot here I pray hertfully to the hye
and mychty God, makare of Hevyn and Erde, to geue thé grace, as
he is gudely Gouernoure of Hevin and Erde, and of all the Warlde to
gouerne thé sa in vertu and in veritee, in justice and leautee, that
God and man be payit of the end: And rycht sa mote it be of oure
worthy King, and graciouse Prince, and all his welewillaris, I pray to
God Almichti, in nomine Patris et Filii, et Spiritus Sancti. Amen.
NOTES.
[1] Dunbar's Poems, by Laing, vol. i. pp. 42, 214, Edin.
1834, 2 vols. post 8vo.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
ebookbell.com