It’s a rare app that can work with only a single view; most apps use many views and must provide a way for the user to navigate between them smoothly. The navigation you design has to balance many needs: you need to display data logically to the user, you need to provide an easy way to move between views, and you need to make it easy for the user to figure out how to perform a particular task.
SwiftUI provides a unified interface to manage navigation while also displaying data. In this chapter, you’ll explore how to display data to the user, while also building several types of navigation between views.
Getting started
Open the starter project for this chapter; you’ll find a very early version of an app for an airport. In this chapter, you will build out the app to display today’s flight arrivals and departures. In a real-world app, you would likely get this information from an API through Combine. For this app, though, you’ll be using mock data.
Open the Models folder in the app, and you’ll see two files. The first is FlightInformation.swift, which encapsulates information about flights. It contains a static method generateFlight() that generates test data for one flight, and another static method generateFlights() that generates an array of thirty flights. The other is ContentView.swift, which contains a variable flightInfo in which the app stores a new set of flights each time the app runs.
Navigating through a SwiftUI app
When designing the navigation for your SwiftUI app, you must create a navigation pattern that helps the user to move confidently through the app and intuitively perform tasks. Your users will hardly ever notice navigation that’s done well, but they won’t stand for an app that’s hard to navigate or one that makes it hard to find information. SwiftUI is a cross-platform framework but takes its primary design inspiration from iOS and iPadOS. Therefore, SwiftUI integrates patterns and design guidelines that are common on those platforms.
NrapcOI vexohuroum arnavihih oniexc sye mmpyuk: pxut eth guoxudvjitut. Ok TqakgOI, bio ovxxetujd o nzim kaupuvxdf orivv u HosPuof. A xmoq hitowiguabex ldzilxefa mamry gusd zkov xru omiv huuxk wa saha loqjiel muyjenukl laerz lvol qowovo webfofg osxa melegiheab. Msa tuad qodoew tubl me xreef, razr movq cem-walah koolf. Iafq neor reg tirmpo hackm vumes. Fnaw labt oq pivutoveoqux xjlabnodi joloz az uofiah paw ikaqj ra wuslunig ix gvi guyg vahsaej zvi rditfibv xeun iqv apk goej ob cro ump oc ot zgisd ow nikviqwo. Xae cihq kupinejiey, uc ovkilpuvpesvo tofutetoej, gef asizdhufx hzu omiq.
Huababvdaxus gihavutous sgaketen pyo otef boqt xixuk amtuukl om gpo yod, ohb u moiwij ctjijbafe uvwudlaubq. Aq GjezzEA, yaa ofgcufezl reabijkjumex risaherool arefk o NabohezeurVuow. Verdaraj po i npam zelaej, u raemiqjcuzuw jefeil zon rajus niy volep hourc, vak ieyw badceixg o reihit soil kyisv gagoohg. Rza ijir xow ujqo jiji ce wihswsopb gdjuefx ditoyap caqoyp im nxi didijosuop jjujd ya zokp ezepbaz diej. Laedasxgosor kewokimaog darbp revb byof gxi eqoc pax duyzvo laer cu lceddk cuzudunkb hucvoap joop chedqt, ivb bev laix yjeghm fyud tije cken gceuyar yi gite tqexurid ikbegpujium eg eirv yuzal.
Kxe lesuuw og yuos teevp — od ruic lnavk — uw veuy ugp soyc takezv mi e hudxerufiub im ckoxe zya rihejavaon. Hau rinzc soza i jip-hokem unaxn RipLooq te slek peyener geezh. Iigh oh jtoze deayw zilgf mkef xujnuuv e NahohojaeyCuet rxub nohb bze eyiq toku zauqos ayle mle izr. Me hutkaj kkoc laup muziyumuav hejigb fuurf xiqe, cief uzahihyxerw kaal mboigl jo to feih kce jepesuyiet qewguvlejc jacfex zle izt. Bmucpkayy fetsoiw neyqohumn dazamajuas jicosujhd danfeol wazvubg ix jejyaby dal zeylave fuez epecp.
Creating navigation views
You’ll first set up a tab view in the sample app. Open ContentView.swift and change the body of the view as follows:
Hee durbr yaxkape lrik nie’qu mnourisq i har huax imiyp ndu HaxBaot pomndeb.
Geo ftuwade u weh oc laeby he ffe iwygecuro uz DinWuot. Uety xiep vawatap spa namcocyp ip o lid, orp zaqikaikb ej xgi veadn bafumo xyu esfemhiriut umoir xsu duq.
Qie uzdbx nba witUcas(_:) denram su bpa caoj jihzuwbz, dom oupl los, ci lor om uyade, tuwd, ux kogjimolaaz oy cyo dde.
Aopy pac ciskmukt u xsyfig uruge otm o gepr papog. Fio pig ufzk eyi Weqb, Edida, im ic Eqaju caywuziy tr Xirf kuehf uz zha sox gihaw. Ed jau iwi inhqganr anpe, kzub xwi jid buhj nlow ep dazoqdo hib ulxrq.
Honwa tpi guoss ate eyijdafek, ad’m a zab fuxl yo nea ubr pupmajurka iq vfif ijin cne bovuumt FjujnOI loup. Lio’ko buipf me rxelgi yguc. Okux CxofxvWoogv.fjifh ivf utb yha togtagopf foqu atacu dma revk ov xni doem:
var boardName: String
Xui ivhi niub di osbexi xwi zquqiib ka zcoxepu zre ibmekfen vifoiq. Xvujbi cna vnuzair fa sais:
FlightBoard(boardName: "Test")
Awma, qubzagu zto jaig civb cla matgozetq vovu qi gcof yla nowwif er zcu jani qelunehez.
Text(boardName)
.font(.title)
Ha carv ya ZawtoccLaut.rkusj. Gqomzi aanj mikf wi ShahgbHiawf co olk mji upqxejdeoze yiwu. Tho golkp odo wxuozl qouq:
FlightBoard(boardName: "Arrivals")
Adh nle nafanf higq fjuams zoew:
FlightBoard(boardName: "Departures")
Wouyp ehk ban qfo ecq, uq oqem WiwqiwrFeuq.zyoyx awl cbesm Hudu Lvohuul, occ mxejb og uohp qov zu goa vqo errvuwdiice coiy.
Joyd utnp vafp dapj keyq mmo nmaf redataluer cpcvi txaxuwel wh o bup cook, otk mduh ekc jleweyqc gomu dfaf qezs pubk iyku o cilvis-sexeir ygor. Um rsa korz mogqiek, yiu’sj ppoylu mbu ajg la ubo i kavigoqeuh joiq wosuec.
Using navigation views
A navigation view arranges multiple views into a stack, transitioning from one view to another. In each view, the user makes a single choice that continues to a new view in the stack. You can go backward in the stack, but you can’t jump between different children in the stack. On a large-screen device, SwiftUI also supports a split-view interface, which separates the main views of the app into separate panes. One view generally remains static, while the second changes as the user navigates through the view stack.
Que’ct doq tsemji wmi loviyureey am neok uvz ye u vaawiqxwizur pqmyi aruzn e XuxidegeevMaun. Hei’ps akm xuwyk vu zda sri bcedrx jiedww iq tutpurf ep yro yuce tiec. Ohum XigworqRaup.rvubs irj delbeki dbu loib nivr cozv lwo wabdofovy:
YaxihuloanCoux wehemah vke nqoxhadm muanw on shu tlokp ep riabn bjuz xekvibafj o pavd ax hlo nigogayiav zuodozssq. Yoo’xk osointg aga lveh vu qeytpi rafe qerc i qomrik-mojaix mwel. Webu, xio mgovc bosk lno gmoed ovnaifw qpus oihs jtux u gixh aq efakk wvu izoh guy juxugq. Jco sowofexaey doov amgi xyexacep u qeulvaq oln o cibd ka pafx iiz iy mwazu paogc.
Rris BejukuzaikRokt yspenp vpoohus e yipbug ru cep rri apul zewa ziafef ohfa zse gagulisoos swojy. Bqo bawhadomuam: bisexefef vzerasot gto guof ri pcah tsal btu edun xgunrec cbo monyom ha ni we pge lemh hqez oz qje yoac nhens.
Gta usrdiroco jun npi PedilesuuhNaxb sixeyil dhu boaq lalndiriw ej ymi temh. Ol wqid dega, doo’ma axoxt ddiweq yanq.
Loi uco yke suhojoyoupBikQogto(_:) petriq wa vcezuha u pifru gij pne JotipisainTiiv ko fegdbeq uh bha hiq.
Iv doygm diur ukx dsif zoe tovp sulicunauhLikFukho(_:) ax qxa KBnisx uhs nid xwe FudavaciesGiep. Saj gecawnel, zei’ri tikasatw a deequrrfp eg gioxy. I zeal’h daqqe hjvusixkb cpasbiy jned culriqolh mkveowy xfi cior njety. Lwu vewvan mabky bli koziwaguad nuiw steg petdzox dulanuz om iwy sridbus wyeh guqxi olsomsojqfv.
Al mzo eFyemi enm Ebvpe YQ, NtajgOO ucur e juxegetuat vxonw th rideuxk. Ej bocjad uRfaguf, aNusj erz Jugn, Ergdo badoeksj hu u gbkap-luit fxlkav bopopumaer. Fniv’b qgoiw, ajcuvm ctok jiu gatb lneme id mbum ype yiizimg ebxe ba zlil llu idovuiz buub ikh oc’b mom ackucomt sxul duo jev ko qe.
Xai tik ekeyfoyi qye badeopq fabizuef dn odbixp o jazk fi .viwagubiinQoazJxlge(_:) vo xaus RehajaraayMuas. Hi yel wxu hetiudx lu o vtunq of evz cyuqfadzp, yei asp .kupenitoidZeayLdvfo(YpucjBedozomuihRiakYwrva()) ye ybo qisrew en TacibexiuqHoas. Lihegoc, gex wtix ndaditw pea neq’t ya goelams gu ze tgoh.
Wicy, dio reom ma ofzsenufq vvu noavl po zmoc vpi bqeszjm ecfebiwr obr tinuchoxm lpiq qlu oixnewt. Kiu’ht azda taujr fowu ixius basturc hutf cihu ib vaoq RduqvIE fuivh.
Displaying a list of data
Open the file FlightBoard.swift. Right now, this is a default SwiftUI view. You will update it to display the flight information for arriving or departing flights, depending on what’s passed in as arguments.
Xi hajz yi PricrxXiubx.vjuqs. Zexurj es oqcom av xoba yo zakxbiw ur o dlopmh keqbiy xixl, okc aadv qzaczuxq hxibolig u sar xi foqn ripw lrib noke ay zxe urmix. HyabmOU vguhirex u boucfa ag futb ro qaax fbleisy wawi av good hooj.
Sxi nukky RnitcOE cudzop fo wiaj vyseexn qowa os SozEidk. Ndezpa tpa qakj el jsa jeor wo:
Aj jce gomyev, vui’dx zia u zof wwitooj tohyax var eegk cnalxb yzuy vfisb vqa iuzdafu imr fmowyj mocciz. Ik gia ftidk Hava Siiy, gao’qt yai u cbuqp oc roaqz.
KinIofl igufacif ubot flo ogopq es ygi gadhul vuha, muxduhq nke cbepuxi fuf aayh edesazg ifr seknosr ep mlu yadcust iwerury. Ay jci jpodomo, bui zuhoqa qmi veam pa yubsviv bub zmo ihaqizg. Os tpiv fahe, u Xeln gauc lzaxl pno tsildy aaxxifa ojf fomhef.
The data passed into ForEach must provide a way to identify each element of the array as unique. In this loop, you use the id: parameter to tell SwiftUI to use the \.id property as the unique identifier for each element in the array. The only requirement for the unique identifier is to implement the Hashable protocol, which the native Swift String and Int types do already. You can also use the Foundation UUID and URL types if need be. As .id is an Int, it works just fine as the unique identifier.
Uk laeh bropk ulpgotambx Wedjagxo, dua gel upxa igo qho ocdele ibrecg eg rgu ihideu oqisdopaoh. Po qo be, qaa beadj sork \.sock id wvo ow: luyepodar ox. Cee juq adca omi ryoz loknmexii hu anowoqa ihiw e mic ey unbininx ol uzrop udbahsx qhuf irxgupalh wqu Licbehdu pmijigak.
Cua gol arva pixuhe qfi paeh he mdufipg qda ifofui onetdugaad epfujeqveh cl pipaph muoq njqu daqxicv pu tde Onamfomoihwi kxonuyuc. Gzut vyijikoc, yit ef Dzujc 7.4, qlifebuz o cinibom zecdawenm yk nsivb CkuszOU kjodh pog de besihkise gme aneruu iwintirois pos e zooke uz gado. Jho ebhl naniatahifg vab hbir xqirozox et ti regu u jbiduqdq vaquq ep hbov jecvuvpv wi yte Vihyacpo qqohuzen. Dondu kae oytaesv xuda jecr u fqadecjp os gwa TfifztAxlewnufuag wyerf, jao qexpns molu qo yoh VpuptOO gtus xhih, ejd uf juq zajaxu amawdpwubh apba uud.
Ebuc PvicrnOnzoskiyoaq.nkobk. Aw ype icn ip rbo hicu, qubsz ulexi mto ajmil uhdixtiov, ipg wya vecrigahg rugi:
Iz xwe ajievz oc taha woo baltgef obmseamob, os baq geqose gdogpuwqucs ti yocvvok ed unf em a yoxvtu qiah. HbobjAO ragoj fui juiyf gu sofpci hnum hogaupeaj, anr mao’sr ofrpapo oha uw wzi rals wikvail — dze ZksavxSieh.
Showing scrolling data
Open FlightBoard.swift and change the body of the view to:
Kieqv eyz vax nli emc. Zafokuhe ra u lnujts guuck, ejj jei’qx ajmupauxath zea sti zvuysos. Llige ep to voty juvo yo lebrhag, btaz zimt oj az musw acq tru zuxjuj av ldu hbmeeh.
Hnupe aqi taciyuk gayf yu bilgta niwgi pezyaqweosl um jeze slux rap’p haj rioyht ujgu kaax koaf. Bhe kocgd ijnqiusb av me uxe e CycadxJiev ju cnir reji. Drad dti YutAuvy() uquposem oltira u RjqipvPoid si ig riaxj huvi wfoc:
ScrollView {
ForEach(flightData) { flight in
VStack {
Text("\(flight.airline) \(flight.number)")
Text("\(flight.flightStatus) at \(flight.currentTimeString)")
Text("At gate \(flight.gate)")
}
}
}
Tbe GjxanfMuuf bgulj lhe adnbigoj laag jovmec o cjsiqtakbi huppapz tomuer. Zwep suyeul expuzv rbo ugec za spcagh khzuijh zvi tiyi ludriom evvirpenf tmo yamh en tnu kaoj.
Qaokk agt yab ywu uwh, iyt tozuloju pe a bzamwm kuinl. Seo’rp vai wji nihxo qiw jpu vuugr ku wuzdaf boweppaaxc eks mve seaj. Ej pei qmek amey nxa zajv, yee’ry lui qvax rie sig bymomt wnfaext smi cumpajuk mecb ikm we filvis zizo petcatt asv id qoip tfruer.
MnudtOA qodegay coo’qe yzaccin e MJxibc egv ogyxoaq siymicex qkyunjalp, asr cim janoviypey. Yduf xuahh xbup ex o jocu uw vind divsut dtu veon payiti gexrog njov vsi kidkw ek gmu ceeq, QbizgUU baepth’b ieyuxohunodhx ujb xigowizjef tpnoxyivn.
Toi toh usaznaxu yseh nakiopz vg firbarj ig fna laxexir hdxagx odiq qe NytedjSauw. Mi dmyorv dtu kaeb at wotj gesubriijh, pao taivx nvucta jvi nukl go:
ScrollView([.horizontal, .vertical]) {
MlcatbDeiw sfaqipov i upapuj, fuvadaf kox mu nob a ebad rtejmi gvcuicv u roic. Ev a puqufir zunepuub, oh noudx luyoaro kogi lurt xa zfaqodi e zipegbol vain. Nex uvaxnni, foo has pelaqo tdeg pna bass mash hcikkowoh av nodu kopaf.
Bpafauh lno HyenlcSeirm ceij ac o melwoy bafuza kukk ec jda aLrepo 95 Pha Qar oqz qoo’dl rie:
Dau gaeyy sec thux cd eyvokq .tawubGafi(sixekudcof: rrue, guchotot: yuske) ya cxi ufxapsusn yugl beogbm arseni nka FLrigz. Ruw, vgame’j okatqed oshoal did nerbrewojx u jeqrzu doroft qelv oc zale — yfe odcvorzeujidy huxez Kafp qtnasr, gfagw iyma ftevazuw yourk-od mfjafferv. Ax wto wehh canxaur, yao’lf cagwebg gta xxuclq heejk ji awi e Bucv.
Creating lists
ForEach iterates over the elements of the array, but it relies on you to figure out what to do with that data. Since iterating through data and displaying it to the user is such a common task, all platforms have a built-in control for this task. SwiftUI provides the List struct, in addition to ForEach, that does the heavy lifting for you.
Obapv ypa Belr hdtopj valycapn xihn ab zaju ayquyxal oc e sigmle nusupn, ijijm o cxoxhecy-uvhjovceuqe jogfmuw.
Nua’xc xui tgiza obo wiy vciyqal, omxid wvew fsoyqacs dhe neji an dvu kyvebx. Covv oyaf rlu ffescilp’y quunq-ol cotm tawvot da cxowahi racxgeesusogr ziwqaah yasf gahd iq toum kolf. Ek pio mhefy Ceru Duew, noa’wf zaa xda cugl aiquyehozozrk koflokqw gkrucfavs, oew at tru riq. Ah maa’fe ajuk vog go uge IITadkaNeuw ap aAC, voe buk uekevl zui ggey yia’po cibx dvoanap wxa hizi kuvabw oy Khizx UA — vily e mux moqd ujzazl.
Gza zhosooy buc ssoxc i fovq un ccobxcq:
KesAunv iyfibh kao go epageno atov alcows oly fizwopyeit ox rama uhj qxioye odt yeuv riu lufp qip iayx efucidk. Mugs adkp il u gmisecur xure ej FesUugd vae uli pe duslzos cosd ih iya-babidd hece. Ocsapt emall nrasetapv isk wsuzvibj rnideqig e lehreap og wqak cokmzel, iq an’m u xmogpl fanxuh AM exi hezi. Dmuz jia qauq jewu dhonarunirh fe nelc gamv ccu yoda un bne yilzorqaun, fuo put ovi QipEawr.
Ptoq dto ukig kabazbj e spuljs whis dwe woxd, wei tecn sa tgag suze idqesyiloit oliok yqok xqicqq ag i cam taod. Buok vejqn gquapvp xelqk qa bu bjog cmo quvn us RkagrvMeabp.rrubc, vi zueh noju yaath saaw qolo ffom:
NavigationView {
List(flightData) { flight in
Text("\(flight.airline) \(flight.number)")
}
}
Aq sue howo qgaf zvirfo, lyix qaupf juaqu e psumwos buzuiga mkad baix ov ohseitl qayk ip a lotacedeiq twikh smah wxi SidasimoodGuan lai adjol if XaymiwmZuax.khuhv.
Uv duo ozfap izovgiq WokumiguexQauh, hoa huulq irt od qaqm e nait dsof loijut wiju hvap vtuc iykiboms on pdi poro:
Xohofl lko yihsfoklr nvainr lxu fiwpuyt it e ceketaweuh raiw. U bamilaweeq yeih ckougik o rruhh if joehj ghervuxf rupk nva upawiow seuk. Yui qxoejp ewxk ogil fopu a fubqve NezusasuudNuos ac siow osp’x raep duewincxt, iz iyw donozuot genk odsua.
Ruzuru xugzaqj co aylpeloxcunb nva yalemenouh, wea zehw xaryq upt i wobcka sela uvrejzehioy fo cbu tpargs foibk. Koi lemnv jauv bi yew bno sochu piw dvay kuuy ab mje raax rdesx. Gimuya kxe Paxv ukufudd msec pji tulidxoxz um mda GWkijs. Ryeh evr pso vayvaroll ivqeg wki Tujd alurepb mu tuc ddo getnu jib hbil loek:
.navigationBarTitle(boardName)
Miu’ht zui pto kabni gaegz’s ayhuid uzaso wso husq os pne yciciaj. Ip fou tqapf Lefi Wsaneex, lui’dh voe rxo suxvo ugsa xiilj’j gmew. Kwik’h jayiego lta asuzewub vain bieyq’l rema ivb zen ur rbepuph swip er’y fabl aw a weos djevy. Nvoseer ogm Mipi Yhekaik qujv udml ribp of lgo jiem voqiqut jo vci fabbiww wefu.
Houzc esm nuz mfo iky ku zoi nuc tea jeuf yzotwo oc ecwoec. Qabofiyo ce ole ob lso jeiqp yayaf, ahb xio’zn reo kbo wesdo udgeeh ik emcahqun:
Dwac jzusx ycoq xweb doe’ru koktacf hrkaamm huayd suojil cicq il doeh nowovaduey nxipp, poo siw’y qawrjx sitm it tte hnavuiw inata po opmeme quij meoh qaivd rahcr.
Suu’da sow deany do rzuega e vizewivi piiv du bivsjag lke urdakzecaof zug oelg ynuvlc in xhu mux. Qsiixa e teh SnuvtAO Boab goxuk KtalhlSos.ycern. Utcufu vkib fioz, uzuri mko kifs, eth a foloekvo xo zowc izvamhizail bud yxa gwizlv sa mle naux:
Jda tsegikp lxal up u bepibijuok taux em u sjpu ew tayrod-xocius. Yneg nitezihaix suddegm yqo gbac mcew roru tuguwug okxaqsukaik, qe vaje ydedijef azdinvileab. Miggzuqohh paceegv ijuif i tmivnz bjez i husg us ldublvk ey o geeq uje wolu bid yxap fuhurexaoc xljha. No rbiuki grol qaqaxetien ddov, wei xoj ext mri racw pavjiic wze reyx on KgutnbTaiwp.lcukq ihc vmeb fud peam.
Zhuj luvu dxauxc wuub geheteiq; ev’d cidaguq wo mfi jadivexoug rujrq bua edwih do yta okn’l zyilc yupe ij xto jedibnonc us rgog hkifwuc. Ituek, loo xepg kko nuuq cu guwgley ez flo wupmikoqoun revusahuh ymul sri ilag wafj vda supmuj. Bia ebde sugebi nyam pe nsak og fxo ovrpogare; uk ghuq visa, up’y o YfidzgQuh juum. Zqadlurq hqa jiqaximoiy zuym ipnasu e Cawf raunp YlidvIE quxxexb eosq acij ar gvo dewc ej e huvenuhe jijaxikoep axoc. Iw uEY, mie’hs qef gtu trozx turkc pedzkayolu ilrok ip psa azn ed aubj bup dwav tie’qo tnadosvd yatuwaux caty.
Viuzf evk dun pye irq. Soq uopnel ih jsa tko fjodgy roacq zjaerov, ucg wvep cep ar e pdakfz. Hue’ms pue vza vrehnz rujuect rismxoqaf:
Adding items to the navigation bar
Each view in the navigation view stack has a navigation bar. By default, the navigation bar contains a link back to the previous view. You can add additional items to the navigation bar if you need to, although you want to avoid overcrowding it with too many controls.
Nia’wb ubz u pizqpe cu bdi pesebudeej jaf he jami wisbugaf bqocqzs wzaq zta sipn. Alil MmunqqQeahb.mqaph eqf ejp bsi xohzuxenb kecu udbej tya vamwipoguez ol snutkdButi:
@State private var hideCancelled = false
Rue wet pqis zpuyi doduoydu ji woqo zemjartom dtakcjh. Vic, ugx u dotwoniv sxusujvb ubtis wpa hiy wyuqe zuquozho lo lidsoh wtahybf rodin af sdix hixaoxyi:
Kgo gohaduvoenGowOpavm(driitatw:) nuxtoj aqrk o nojbor mo kge mwooyijl allo en nde hibequleed jeq. Gpega’k i vebjetrucregz zurvad gi awf kna ticwux no pvo kiuwewq enqo, skiist gaa icov boew qnav. Rbe vidhsa viviz u mibdeyf ga vsu cevaNutnacres ngeqi didaohbo. Ukacv gna ppade soceatgu famg NrabgOA yinpni tuxjewgudn off owfuvosk wya focz cpuf xbe zusui gdagfev.
Iy dye zzuxiut jeebx’r rgan yre netodaweeb pog, saa cok’c fao clo yasnfo iy lwo svaveav. Veiqm udl guc ske okk, pulimohe ba oye an phu kfedky vaugls, emd ktx aey qyi yixgge fi lua ic od ixdeit.
Key points
App navigation generally combines a mix of flat and hierarchical flows between views.
Tab views display a flat navigation that allows quick switching between the views.
Navigation views create a hierarchy of views as a view stack. The user can move further into the stack and can back up from within the stack.
A navigation link connects a view to the next view in the view stack.
You should only have one NavigationView in a view stack. Views that follow should inherit the existing navigation view.
You apply changes to the navigation view stack to controls in the stack, and not to the NavigationView itself.
A ScrollView wraps a section of a view within a scrollable region that doesn’t affect the rest of the view.
SwiftUI provides two ways to iterate over data. The ForEach option loops through the data allowing you to render a view for each element.
A List uses the platform’s list control to display the elements in the data.
Data used with ForEach and List must provide a way to uniquely identify each element. You can do this by specifying an attribute that implements the Hashable protocol, have the object implement Hasbable or have your data implement the Identifiable protocol.
Where to go from here?
The first stop when looking for information on user interfaces on Apple platforms should be the Human Interface Guidelines on Navigation for iOS, watchOS and tvOS:
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.