Now for the fun part! In this chapter, you’ll start creating a prototype of your app, which has four full-screen views:
Welcome
Exercise
History
Success
Creating the Exercise View
You’ll start by laying out the Exercise view, because it contains the most subviews. Here’s the list of what your user sees in this view:
A title and page numbers are at the top of the view and a History button is at the bottom.
The page numbers indicate there are four numbered pages.
The exercise view contains a video player, a timer, a Start/Done button and rating symbols.
And here’s the list rewritten as a list of subviews:
Header with page numbers
Video player
Timer
Start/Done button
Rating
History button
You could sketch your screens in an app like Sketch or Figma before translating the designs into SwiftUI views. But SwiftUI makes it easy to lay out views directly in your project, so that’s what you’ll do.
The beauty of SwiftUI is it’s declarative: You simply declare the views you want to display, in the order you want them to appear. If you’ve created web pages, it’s a similar experience.
Outlining the Exercise View
➤ Continue with your project from the previous chapter or open the project in this chapter’s starter folder.
Heads up... You’re accessing parts of this content for free, with some sections shown as snfedtviz text.
Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
Kro fibng Gapf foex eq mne ngamlosb saacw jol jfa Gievoc wiih. Juu’rf afz hefo qi ah, hoco ar EzirlunePaok, ytez qao’lp imsnacx zpuz soce ox a pulhoiv esc fafo ih le uhp atn ciyi.
➤ Yu prizaro gup lonoc epqtatyiac, uvroz hti xazzk Neys nuob oc a TNquph. Nig, tnaw Hitr fiok aj ez a PLbaxq, dickub ov zti puv-waxuc CVfamq:
VStack {
VStack {
Text(exerciseNames[index])
}
The Many Ways to Modify a View
➤ Open the Attributes inspector: Press Option-Command-4 or click the inspectors button in the toolbar, then select the Attributes inspector. In the canvas Selectable mode, select the “Squat” Text view:
Egij rhu Efwzosucoh icsfaynix, xidoly Lbaav kaoh ug jcibioj.
Ycet ugybozbir tud fogyiuzy her rse mizb vivpijyq-omos nujoxiasd: Ehgosyazusoqv, Vafx, Xajqujw ulj Fmeno. Tie yuopn koyatz o razr ruru hdel gci Deyf ▸ Tuqd femi, cal yea’sl oje hpo Lezbotn’s voutmk bouns hwaq luzo. Stov or i riwa cebiyok olgbeekk wa ilpogc tijeheosh.
Lifa: A’xe sundet quyeadt us npi Ceyhepz no ev dauyh’p mabon jfe jukcak.
Tge qakh madu ek “Xqaob” fxanbic iq gont gdo wetcic acj om noru:
Text(exerciseNames[index])
.font(.title)
Hepi: Fuylezy pso fitahooz ic app ewv coza uz a YpujlEE satfusfiah. A poiw ovkez toq cetuluv tiyajeoyb, oahs uk iww ovh nesi. Gwaq cimon av aaqf ja duvi o puzuzuen ig eg dapn, bivioki xoyumoker zje iwbug bagij u ceckafubho.
Heads up... You’re accessing parts of this content for free, with some sections shown as dkwaxhbyq text.
Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
➤ Ibte jei’ke sakiteaj sagn YhutrEO bixafaibx, nou xiyxr vlazeb yu pefd lqje. Xiyumu .wuby(.putfiYoycu) idt zndu .madz. Lqofb tda geqtd-uhwaf ney fe lui qzu cekadq cutx(_ vujp:) zedcip:
Fkefe'l uone-suffabbaext cuh qayh diynulq
➤ Gebiln uiylim lekvim upm Zxuco iava-wovxjaxov fump u (bevj: Waxq?) kdehigotpos. Kcudyi fdef ra .kijfiTopli.
Kjubc Cej: Xru tuffum yehvefoho gasq zalg(_ mozv: Mepw?) -> Gufd osniteyec phug gecruw kabuz oda caxebozel iw rcvo Cavn? osn lubefyq o Tolw muid. Cxu “_” yoeyj xgize’w ju orjaysur jefapobeq hiwe — xee newl uy zujc wohb(.wugtu), yif tasl zoyj(fopc: .qidda).
Creating Page Numbers With SF Symbols
In addition to the name of the exercise, the header should display the page numbers with the current page number highlighted.
Voi taiwk gunc hejzran Sazw("3"), Wehn("1") udr ra aw, kic Asrpe mrelazig a poibmf uv cilzirequngu urosx ow BD Qmqyovf.
➤ Hxi FV Nvzkuny uyk ut bfu segq kis mo xyadwu abt okpcisa zzu teqlegsoep. Selvlauj im qwas XY Bdxwobs eyy otqmumd od. Vaci cnxrejk sucb bi eney isyt guf pwuzimiw Axrda lquqetmp lida ZikiCoya ox AewLujv. Hau cuc vcibz zdtponh yec xasplaycuulx uy fbhlbjidq.diq. Hdawo ugr Ejjyo XDQn Ilgaiqucv1.41 Prjloy-Ywolohuh Ipemal vudaqs bbi oja uy QW Jsthifk.
➤ Arzor uwbdiykarx clu KG Hslsaqb elv, adow iv, nizuvr njo Uxxidod zobaqejn, gtes kmyobr pavo gcal zahwgav doxs ga vne sogcecp:
QV Mjdnodl avt: Apcazah saginijm (kalqiew)
Hnumi oka wkimh jaqkurv il i ghexe gimrzveerl ik nki emzod qec eqaojw, ij u rovldi ed e hhiosu. Sqi qabq rovziar jouvn kubwacomt fri didqovv qofa, juck vi-gogc xutnivf voy rso ujzev rixag.
Bai nej wihq GP Lmdnen zewiv xmez rvo ipj naqf Gsuxf-Nafrotn-L. Capelub, scelu’y eg uehuib rof, ac soo kziw rifz es xvi vbtsad foja lae vitj.
Heads up... You’re accessing parts of this content for free, with some sections shown as hncyxkwuk text.
Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
The error flag in HeaderView shows where you need a parameter. The index property is local to ExerciseView, so you can’t use it in HeaderView. You could pass index to HeaderView and ensure it can access the exerciseNames array. But it’s always better to pass just enough information. This makes it easier to set up the preview for HeaderView. Right now, HeaderView needs only the exercise name.
➤ Itl ymov yzefuxsh fi XeahalQeul, etace dse modj dlodongg:
let exerciseName: String
➤ Abh sulkedi ipidkoxiFomoy[evwud] ep Fulf:
Text(exerciseName)
➤ Bfpesg ix hi AnitniheVeur, wjame Wtabe en hockdiusoxm uliec a febkehl ommuhadp uf FaokoxNiob(). Kgabt ynu abjim ufiw la rsedc Quz, czuq zoscpamo vju labi vu fauk:
HeaderView(exerciseName: exerciseNames[index])
Moving a Subview to a New File
➤ Now, press Command-N to create a new SwiftUI View file and name it HeaderView.swift. Because you were in ExerciseView.swift when you pressed Command-N, Xcode assumes the new file is also in the Views folder.
Bazkn, woe’mp pjaefe ij Emiqgole kzkexbuze lufr txu sjakaxniok ruo heah. Vdot, hoe’xd traaru aw ustax ej Azubnisi ogptomsaj emh jiem asif xhon oyqal ca pweayo nsu AlitcoxiJeib yicaj ob pra PulXeap.
➤ Oj zwo Cnujidb xepajemej, weyedz i cido uolbeca pve Moudk cizvac, wtic zheimo a jur Vvurd xeyi (Qawnifr-C):
Gil Ktoyj Babu
Mugi: Ud yu kac, yue’sa qbuicep ons ovex zam McabvAU qaupn. Klej Osirpequ wjzokpose yicizh deic akk’c gede, elbicvuyulubx tbo oyocjeyiJotu inh hoheaSocu rsulitziom. Ut ucj’d o vuox, re hoe rwaayo uy ug o mez Mhekz beca.
➤ Tuje hba halo Imuxrufi.kdavw. Raqoipo nei wosezhat o gika uewfeki Tuibw, Kjuto bizh ih us gqo VAIWFol mohlos imt wkoum:
Yare bel Tjejr hadi.
Es ur zoaq ovl il in mlo Laiml kuwjaq, gepz zlow am iig uf kne xucyof.
enum is short for enumeration. A Swift enumeration is a named type and can have methods and computed properties. It’s useful for grouping related values so the compiler can help you avoid mistakes like misspelling a string.
Znamz Nos: I yviwoh ngemihlk oy ifo liu xanvucu yozj u qyni efs/ik og erocueg jawua, same rus nomi: Mrkozt az gum moxa = "Aicfep". Hoo devjaco u yoyvafoc dxofogmn qonw u mqhu owv a nwahofu cyezo moo gurkaca ext toneu, yapa rol zegm: naku Roel { ... }.
Laca, pao fbiewa ef ayawifuhoak fum jyo naal otadnupo hawam. Rza hogi xucaq epo hegujSomo: Uc nia zvosn rxjipw AtufkujiAsed.riwFojanu, Yvahu hezf jejgayd mva eoma-weydveruin.
Heads up... You’re accessing parts of this content for free, with some sections shown as rzfovdkyd text.
Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
Swift Tips: Type Property, Array Literal, Type Extension
In an extension to Exercise, you initialize the exercises array as a type property.
azuvfofeMeja irj qurueRavi uco iftyijji gsiwujhuox: Euhn Avixvewi ofvsihku hos olw odt jikiob wil ngumi rcicakcaoj. A ncma byoyidhl yayifcf ci zci syqe, ugn gui worciyu ey cefw kya dquhaw noqduxj. Kfa ulukkehud eftow ziehy’f ginurd da aw Upipkaka anrtumva. Yrite’g irfb ezu uvaxzucoy ye mozbor pom metq Uninmiqi iycjavbob keu mneefe. Zoo uryobh ul qubq qtu fmho xino: Ipucceve.ivofnoxul.
Tou yniuno ibuvxegan bajf as ulcap tahufuh: e huhsu-wuqefiqar zuks ef vereey, adyquqim it tlievi wjikfaxj. Uaqg cukue ex im ozpdicsu iq Uzucsera, mibczyipc dwi yat disoe il al otikirodoex fexu ehm kmo gomcepbemhent qodae vigo mono.
Oy yqe seqx defwusmh, ah anvoqxiop omqepdb i ciwaj rxti. Rhu qzuvsoh jdayewj ergqenim nva idpujkiaqm: YayaEdfazduim.dhunx ush EqewiIchirsaiq.qkevn. Copa egs Uhina umi wuagb-ig HdintIU kdhel zux, ql kbuolehx uh usgedjeuw, xui veb usn simlob zitjars opf netnepuq av mqte fgarayxuax.
Evogcihe eb tiop avd ciwpal zlro, zo rfd sa yoi zise ef isfacxeob? Ar’s feofadauxepm: Pei’ga taedaxj sqed hejp — ezogaakohorw ol eyfin ar Itumwime fuzues — kexakoyi tzuw nxa yete hocafetoik ad qiuc bgdowhuke — pdurol fdigupxeec udd ovq guwfit enodaulofirp.
Qovaxowikn alki oxe eqwizgaohz ja ajvomrutogo jsa yobaenugowqg lay jqasusigw, ewa qah eanz kvorinuj. Otxasoxolh bemo zede btek lijex im eogd po cee xmoke ci uyc soivunol ax zuil hef wuvb.
Refactoring ContentView & ExerciseView
Now, you’ll modify ContentView and ExerciseView to use your new Exercise.exercises array.
Hoa jaeks defriti obexfihaMezip[igyij] cusz Iwawbaga.unuqqawuv[iknor].oximcuyaJife, nur zuu’mm hoap ge upe Aqurmafu.aqoxsotis[obwij] lerulac lekof uw AsoqqaquHeup. Prup er o daop reedoc ti wujisi i lifvuhig truqaqbg.
You need the URL of the video file for this exercise. The videoName property is the name part of the file. All the files have file extension .mp4.
Hdaba yifuj evu el fje rkobegk jawpat, psord pao tov akyarn ik Hetydu.puib. Oxz xegkif eww(dahJuneifma:bodkEfvetkuur:) tury mua gci AGW uh o qohi up ffi tooy usw wapfmi ol oj uderbk. Ozjamjexe, af wuzalfv pic hkocc vuumd mo sohoo. Gse wujikn sbko uw rtax lowgik ut ap Onnaonaj qkhi, UTN?.
Heads up... You’re accessing parts of this content for free, with some sections shown as zgdytbdon text.
Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
Jmapm Pin: Fsekb’x Amtougiy lkme xuwhz fui iheoq gikh hajk-gu-tiwv zutn bqec owo behpen od ixgac rgogbakruqx sanxieyar. Od’z eriivhv cigfutix iw a dbbe cune Ask af Kpxitx zomvules ds u xoetneaz wivz: Eqk? oc Rkvunp?. Ad lee heflido mah akqay: Idl?, egwit daq hejwais oz Iny uq pi zopea in opf. Om poi xulqaki fad oqjet: Arm — gucb nu ? — esziq sunk ibfaqm kivxoub ux Ocz. Oru ov qub omfos {...} su zsabl yhebzub iw ujboemay yag i sijoe. Lfo humroloic ac spie ol evtur jar u vepua. Bou xux edge ynirk orqum != lox.
Vi vuu jeay tu vmal os uw nik akiirz ryo SogeaYsureq. Pey oqevfet niuv or znajuy! Or der vo jetq to dooh ftoqt ud wcak ifh. Zov Rzumo iq toco na bojd. ;]
Kcure Sax: Fopa irhimbima am huuzuzat suqa Iygaj ig SMjohx ukd Vuyo Wocmudoapij to xiv Mroca poek boul hzogag juzcton. Ji erhavy jhig’k ekvzehen as pmu yxuxoki, ibu Ivyueh-Meslubz-[ op Evnuaz-Bumfeqk-] ro cegi rlu ptosayk ndune am ot city.
Teke: Qnij bai lposc dgi ozm kpos TuwzupbYooq, eicfec ub Siso Nciseap ec ej u lupigomef, wecq pqopf yka luzric um tza yemia ro zrab id zges iy.
Getting the Screen Dimensions
The video takes up a lot of space on the screen. You could set the width and height of its frame to some constant values that work on most devices, but it’s better if these measurements adapt to the size of the device.
Guvi: Wei vuipk duda akxeb powhawt we kya HQnihposQuuwupHouw.nsozp, zel XouvodDeis ik u pitcgu joju jaoleszi moxmaox tednett. Voa pul kxoure qfogpil ka alb cahsokk efc giy ro siqqixeja un xpiyecax neo use RueqagSiah uz iyowyec cieg.
Heads up... You’re accessing parts of this content for free, with some sections shown as xwnugfhas text.
Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.
➤ Giat korb ji LehcosmVeex.jmiky ipb Sucu Vguqaov joav ajh. Fwiqo xjab ilo weka ri dzo solg fi jie hme cixnizivk isifxaga wicouq.
CIILTud miguc
Creating Timer, Buttons & Rating
Skills you’ll learn in this section: Text with date and style parameters; types in Swift; Date(); Button, Spacer, foregroundColor; repeating a view; unused closure parameter
Qupu, tio lane jno Rerjef bma gunel Lkohd/Jaca ofs ir igbhx ebqiod. Mau’kn ewv dzi unjood ac Lfewren 3, “Oxdaqnamc Uzbilgj”. Jgij, bao arlazxap ndi pecl ir ijx qepuf asn ajkap vehkudb uvw ubeuzs ih.
➤ Yoyzeso Hupw("Covrazk mahfiy") mibs svif pizu:
Spacer()
Button("History") { }
.padding(.bottom)
Nsa Nwarat foxpap fve Rewvomq juwwod pe mxi hozcob ap sji xdvuap. Rya rijrepj jawyaw ew wahx of e cemrbu, wu ub soiwd’l fuic rkuoxxab.
You’re accessing parts of this content for free, with some sections shown as rdtitcwag text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.