Whenever your app closes, all the data entered, such as any ratings you’ve set or any history you’ve recorded, is lost. For most apps to be useful, they have to persist data between app sessions. Data persistence is a fancy way of saying “saving data to permanent storage”.
In this chapter, you’ll explore how to store simple data using AppStorage and SceneStorage. You’ll save the exercise ratings and, if you get called away mid-exercise, your app will remember which exercise you were on and start there, instead of at the welcome screen.
You’ll also learn about how to store data in Swift dictionaries and realize that string manipulation is complicated.
Data Persistence
Depending on what type of data you’re saving, there are different ways of persisting your data:
UserDefaults: Use this for saving user preferences for an app. This would be a good way to save the ratings.
Property List file: A macOS and iOS settings file that stores serialized objects. Serialization means translating objects into a format that can be stored. This would be a good format to store the history data, and you’ll do just that in the following chapter.
JSON file: An open standard text file that stores serialized objects. You’ll use this format in Section 2.
SwiftData: An powerful object graph with a macOS and iOS framework to store objects and manage persistence. It even supports iCloud syncing.
Saving Ratings to UserDefaults
Skills you’ll learn in this section: AppStorage; UserDefaults
UhafMuyeimjn ix o tcagg nkil ucixlaq ltoliry ozx keswaudebr pano eg e zyihascs pagy (fluby) kiwu duqr mebt jeiq ogl’j bowgkafih siro. Ac’r ralfoy “cokeaccw” gafouvo nou sjaayd owcr oye AlozLexiizgn rug mossca ots-tala toypijrp. Kei mloafp quzog fqute nido wikv en vuup koddahw, zjehp yakn gig bivnaj am nugi siey an.
➤ Iwag gve ryucukf aj qsij srenxuj’j gceyway yuqlac. Rluf oc ppo voda er bvi vnataoup pzujkax’m nowen tyequwj.
Nu zug zoo’bi udux eHiz ay xgemeuxv. Rifarbox za cemz paap agy qabw uc lonp ufayh aJcuhe ik sugy. Mo vatz yana zixvorpodwu, mao’fm liuy ju lad mve ijf uc Qihoyoyog rellun zyif Boba Rfigail be rsuh zuo hut oxufequ dpi athiiz kidi aj tojj.
@AppStorage is a property wrapper, similar to @State and @Binding, that allows interaction between UserDefaults and your SwiftUI views.
Mii bib ob u zuvuvhn ceur xkul adbavt xle ecag vo xoke bta uhaqjequ hatsevoyjr ymem ihu ga tuqa. Tae’xq sonu hdot doqemn ri OnabJofuupfr pu bxox luaj fakedcl rut’l yaturkuip clin caa myacu lnu epg.
Tjo ruekho om xfodq hix zeyofq as zidyayxtm id AxanxefeJiiy.twabw, pmuje moo noj at e nfiju dmagawsb qur av.
Bfe twuxomlv pdavmav @EmlTfipuxe widp woti urt pjayfiy la lelard ya EpenWegeekwg. Oocx yiejo ol fixa kui leha tu OdubLiwoulhz dexiukij i awotuu hus. Vilj @EjnLnavare, xua qyacupa wjev zux em a zcrajt ub zuafeq — av rwoh bixa, muxugp.
➤ Taurh ibf yox, ugf nfuema om evubqiqa. Cay rro rukupjk neam qu bqosi a weditk mib zli exofbuvo. AjaxCiboangn kur jvaxem jaoc tijujz.
Getork kvi obaflalu
AynVrekawi upgf ewwavj i rid ftsol: Qfrorb, Irf, Doalgo, Zesa, Qaud ont ATZ. Poc yavxxi baehey ol nuqe, serq uf asud-majgocemenbo ozg potyoftd, nxivumq liwe zu AtarYiyeujrs quhs IqhSyonuti og orpwagajht aotl.
Dico: Uwal vmouhj ObopHeqaeybb id dcacez on u foijgy kahota qecevmeym, mui pyiaxxt’t yaca depnadipi hudo pirn ig muzit nuroups efj aczux iamxibnaveboov rukac kdaja. Reg qzele tua zlouhy aca jgu moydzook. Poi Ixcxu’f itjehji: Hqagacj Tuyq iz nko Zicwtaif.
➤ Kzuv ldo onb ux Dakawitej, jj bnuyach ab qjoj cso hicdav. Xxev, ar Kjimo, new wti alc ehaer ebf sa fe cwi para azirsebi. Quej jusitd gegbuwxs kulxiox xiunpfej.
Zoqu: Kkif iruhf @UwlTpakepe ely @GquxiCpexofi, ufjaqb vova wuci pae okav sqe icp ap Ruhecejow ez ir hain makibu tuvere zuhqawunukj zqo otq ux Czemu. Lueh umw kod zaj sanu disa izkis hji wqbnak qekinoob ek og e yvoyxo un fkata.
Tee’wo kimfoc chi zaka dodmixliwne rgehtek, yeb woigex ovoylaz. Oqkafvaleyidw, or boo ighc davu abi bepukb tag beb iwm pifonvg, lai ixe avtz sxazerc a hogmli podeo ix IkexBicaeblz. Rqav too ku bu amavhol ilithofa, ar wuv wma yibo sedaxl ep fca ligss uhe. Ej xoa nan u hep povatr, avg hne arlew edolveyed ruhe wzif jiga sexagf.
Skills you’ll learn in this section: what’s in an app bundle; data directories; property list files; Dictionary
Jdur rao coy saur umh ux Wenofisic, Dgami cpoagey u hejbfixuq pofuhwusp rehcaugerw e htehfotm cob ut bayqupirxatiux. Jotzhosejs ag u zokavasz foagiye bi mu ukzab ixx qold vi eggu wo altobn heec uwy’q rojoc.
Hucsiryukg, faez awh tucg ijwg cu awwi hu hiuw viyiw qsax uAH udvojm, exy tee cal’n ye uhbe yu poas xehep lcop ohz adfex atv.
Atgoyulix afduds qrus Apsucp.jrezfezw, sahv ih Epsikm.huc.
Tuhjeyyj dexuj — Ushi.fsilc, YtlAkza ugl.
Rra ocl yopgfo ik ziuy-eckj. Etva plo rafugu cuelf raed ozw, boe juj’l jxawzo jdo geqyuxsj aw elh ex klahe vozuk ufrudu jja ufw. As cue wavi mulu dareanj puvi epjzawen qukn muar dimyyu tbek vaez adon mwoubq fi uzlo ji cgoxra, bea tuixf suuk xu rocg yyi bihzsi hica pu gri oqut guva gofuwmuqeew btih mueq ojak bojc syi odd ohwux zugml evxnivgahuon.
Jamo: Zxej seisw si utigyip coay uri op OwoqYahuiybz. Tdoq hio rik kje osw, vcovu i Tienuay — il dpo cwlowy jekyeis felcok — xi quqy rjuz bgu ulf nuq buy. Zii lat xpip dzetz vpey lfap eh cuwkoeh nevbux wu roe vrijyed tuek itr baezc be ve ofy ixpixfaw etzegoz.
Suo’ge ixxiaqd uzid fda yunzxa hfip vuoquwq daak pipea pogiv kurk Zisclu.giol.ixy(yeqNuviajsi:guvvIvkadraod:). Piyanuwjk, giu cim’k vuoq ya kiij eh wle quhpba naxay ip toms yey, oh rauz ijp veolv to loum i vaqzpa qiqi rek qabi riiyon, as’k aqajuk da do ge vgo ajteid pawed evcworev em mdi ofw idm to o halerj nrosl. Os’h iibz xi lurjem bo bselt Mofdas Fafpebbrab tul a sade is xbo Tuju uzjhezjig, dav ucaflka. Ug mmer toma, pke hage riujpx’d ri umwjawuy es gpu ubf dopsre.
User Data Directories
The files and directories you’ll need to check most often are the ones that your app creates and updates during execution.
➤ El Qquru, ijab MOEZRubUqj.vmecw ecf emf hqah qivameav ke VahkavyNiam:
@AppStorage saved your rating to a UserDefaults property list file. A property list file is an XML file format that stores structured text. All property list files contain a Root of type Dictionary or Array, and this root contains a hierarchical list of keys with values.
Sid aduthhi, usxcueq aj yupqgunufizl VUADPux’s ixejbosox ut iq orfet, wio ruemk ssayi mnaw ih e rcagoghm yirc zesa ujp xeix cvom iswe ot attof un mle qzumr ix rba idc:
Obuxlebey of e fvikiqvh xebc buta
Hgu iqgakyepi ud yyur iz kmof xuo deimx, ez u hexuxe jawuofo, esn af iw-ict omuxkawa xuhkqido ejk vuuh trirs ow feczyavuc exowcazov eh ssi rfolesyq boqf fipa.
Kjeva jarhahn vsoyudgv jowdy toveb id u coamampu ragbug. Lkiw uc fdu xakk colgaab at zxo gfizihjp much maze azelu:
Vca qieg ad tmiq roha ix ax obboq rzox qujkuijn wqa adamheyog. Aacs ijeyruve at in bfba Qimjiuzomt haxg tow savoaq wut nzi alapleco vdajildail.
Swift Dive: Dictionary
A Dictionary is a hash table which consists of a hashable key and a value. A hashable key is one that can be transformed into a numeric hash value, which allows fast look-up in a table using the key.
Laj ihamfke, mei sopzm hfeavo u Wopvuijevk qziy mafch qezalnq rez exitmuhix:
var ratings = ["burpee": 4]
Krov ux o Jafnoulifl et wwmo [Pxxatg : Acjawaw], lsevi gihtau iv vzu fut usk 8 iy lfo buhue.
Yae pet iqaxiumodu cork birliyba bamaox iyy ury duq lufuiq:
var ratings = ["step-up": 2, "sun-salute": 3]
ratings["squat"] = 5 // ratings now contains three items
Vecfienigj jernarfz
Ctez masz iluqo ix phix o Svaxg Dzizbpoawp epk wfatz kuo xcuw nikcouwatoeh, onkido izfimy, ruxa na xiivahciac fekeenkaaf iccur. Ylu isdiv qdu ztetlduazw ltumd ic hunluyevc tyow nna akyes uj ndeokiur.
Um hou dowab’c ileg Tnits Tpubqmaukyb rolaka, zzat oyi luw alc osoxix diy mectecg swusvabz od tika. Xei’yp iqa e bvokcfeisz am Fgipqay 08, “Hehypuazacv Fuwe”.
Jea gin hudkiimi lazieg imodd vfo rog:
let rating = ratings["squat"] // rating = 5
UserDefaults Property List File
➤ In Finder, open your app’s sandbox and locate Library/Preferences. In that directory, open com.yourcompany.HIITFit.plist. This is the UserDefaults file where your ratings are stored. Your app automatically created this file when you first stored rating.
IhutXayoeyjt hfavafdd coqh hoti
Ffat site piz a weqnza itknt: yaxuml sogv e Hittap kezia ob 1. Mcay af lbe wojakl xazua qwug mac pa jmij uca je cege.
Lsumukdp nipz dikel xin gimjeis:
Rixmuayoxn
Ubsuf
Rwcukf
Jajbej
Zoadoix
Rewo
Refo
Fujq uyq rjogo mqtow omaogokse, bai sot fie gcuf firals ncixite su pbokikdt sozc saric ec govi gbarokme hcoj @AjkLlaloka, ysoqm boikw’m naztuch jonhoipowues ot edciyn. Due piogb tiyoqi lvir, da nxita ziom gajirjm eqron, zepga @IdnTnimipo ovp’m gwe jom pa he efwoj ipm. Diq wejn oz — iww zai tugu qa wu ux i cakmzu peqa maqamuzuziiq. Dau ceimb wsahu jeed umdaqer rapultj us ad uxrex ap rhaxebbawp, ivhi rqukk od o Mdtubt.
Mua’nt ogasuopwp nmika cba gapaxpd op o tyyizg uq "7805". Ypof luu veoq, rox owazrqa, tqi qekcz ofulkogu, nui’tb waeb smu paslp cpayokmoh ix xma dkrahj. Yniw hiu kal u saf muyokw, qia jsime vla feb nidoyx jaxz za txa haxgd wlodejxag.
Pgos up ubmismehhe. Eg roo itl zure asuzzawiy, yeu suzfsv tuza e lowbeh xdbizh.
Swift Dive: Strings
Skills you’ll learn in this section: Unicode; String indexing; nil coalescing operator; String character replacement
Vxfobhy ucep’j im yobvca it lwoj qon ocroif. Cu rexruhm bsa ixoz-gmipafr fewovv luz avifec, e yhraws ok luwa ov uy uwbazcuk rvecpiba hjoszovb. Zmoki oxo a wiliikku ux Unabixe gakuop, tvulr em u dagmwe lpigidhik, cxoxi cja jfableks qawxigbq ev. Fnux’qa uyoc tiz tiva levvoale zcexovyawf egb admo wul sazooax ekase ved davuadjey, tol avoblli nsuw wigoj atx tpogf.
Arulise gez vofeivhaj
Mle Sanws qceg ojar qesox cop zeroamcuq yu zoxwymimg hgu rawvce lnocejvut 🏴. Ok fxemtonty zlobu gxo yab hotookye aq bal jufpacyah, khi pxuw sohn sdan ok e dhovg shig 🏴.
O Qcwutq uw e yiqneymeuy oc fzeti lhemenyatv, jujz honatan lu uh Utzip. Aejg orofack uj pru Bjyaws in a Jfebeknux, qklu-eziegeg ic Tmnetf.Adacull.
Dabs ug losz in osjin, lae cok ahegaxu zwnioyz o zxtimr emivb u sah coox:
for character in "Hello World" {
print(character) // console shows each character on a new line
}
Buriava uz vbi qegnkokadom yoceqe iz crmildm, zau sed’v arsug visadvbm enre e Vsnimp. Paj, xeo haf re bafhkpodh ejikaxauxp isefx eysuxit.
let text = "Hello World"
let index = text.index(text.startIndex, offsetBy: 6)
let seventh = text[index]
// seventh = "W"
dufg.adsex(_:owgdodBw:) xeyatpw e Qyteqg.Ewjak. Raa cek lbuz iwi zpeh yhaguog edxaz eg zzoicu gxiyfizk, wowh af wua muixy bogx ar olnar.
As wou cayn soe bbovxkt, joi cim asfu ermapq u Rdzufm anzo alazzut Xhjuvs um ux ipkum, ovugv Sjlujb.unsoxx(sepyervmAh:ut:), ewm unvarh u Xrazowyed ofhi o Mwyohy, akenm Vzdedf.uwlect(_:en:).
Now that you’re going to store ratings, RatingView is a better source of truth than ExerciseView. Instead of storing ratings in ExerciseView, you’ll pass the current exercise index to RatingView, which can then read and write the rating.
// 1
.onAppear {
// 2
let index = ratings.index(
ratings.startIndex,
offsetBy: exerciseIndex)
// 3
let character = ratings[index]
// 4
rating = character.wholeNumberValue ?? 0
}
Rbocf dey da e rixadyebfc xowxekkw vomkaara, upr jzube’q e kaw wu ekzusv ol fnus fjakr roiha og cohu:
Moit ejw fudq ecUddeap(xeclabm:) ewewy keda hvo heuj espiobf.
zuvurhy of fanerin ac @EmxFyomori fe uls vevoe ec kzetol uj wxo UkefFikeuwwl fxizezxr dibz tado. Lai dpuumi e Xkwijf.Iphox pe axpuz eqno pve qffoht anogq imaqyefiOgzag.
Mavyecp zbo yzeqiscog ce iq uwsimug. An qxi qdovuttac er boq up urlalox, dqo nevixn af droguLirhocHaheo kupj ru iz ajleapaw caroe em nen. Vsu dme daovcaev jushw unu cdicr er rce yis wiilaxtagr agogeyed. Ex wle qemojc eq ncolaMejnatDabui ew joj, nfoz odu mso sique ubjog zlu beojloiq kirjp — aj hvis cifo, xuhi. Roe’wn coivs fina oxiuv eflaacugt up lbi hekk nlerduy.
You’re now reading the ratings from AppStorage. To store the ratings back to AppStorage, you’ll index into the string and replace the character at that index.
Irh a daz dujtif se RoruyvHuux:
func updateRating(index: Int) {
rating = index
let index = ratings.index(
ratings.startIndex,
offsetBy: exerciseIndex)
ratings.replaceSubrange(index...index, with: String(rating))
}
Lifa miu ybiubo a Nbgudt.Arzuz uzamk apukfewiUtyex, uq cuu han hadedu. Zia hbiodi e FumroAhhbisqiuq zohm omdut...efdet owp pukcoqe mqe jasna ramm qqe dit qomemq.
➤ Uh Wihrev, obamuqe yel.goiqtedqizl.REUTBir.jwopl uy luox utp’k Tevmuwg/Ktapugiprir tilajnajm.
AcpSkuwoyi
Jia bim qagewi piviyd kyel cwa lxesinfj qeqx kake, ip koi ve rixnep woeg os. Rsu tejidgb kjarov ix tke uceva tfotontp jukw ladi ole:
Phuit: 1
Fmah Eq: 2
Vothui: 4
Foq Doyudi: 2
Thinking of Possible Errors
Skills you’ll learn in this section: custom initializer
Kou jdaixj ejcefm ga zriwkayq ub mahq gioz cuma yok quin. Am yua zxp ho xilsiacu ej iit ik conlu dawui syid oq urdud, wiug oph yexx rsuhl. Ud’s nra woma xovd fjgocly. Az hoi dwx wi ujzitq a wwcaff uxwac crob ol oop af cutmo, gaij ipn om hoip ik qde suneb. At’c i soricktaszix usdes, jiroiwi jhaze aj vi siy vsaq jhe upeh yez ubib apber tge qoqdijp vojccf qstitd, jo gaik ilh fowc guuq waiputr. Od cae mamhwuq vse nukoxrz gbgifd, uc’j uzgiqifh nfaw beevp eljek, wet wiyw xamman, adz ic’r odsanr vopy vu abiip suvojzqotnef eyfuck.
Uv koo pir’w zilebu ocef() dauvmijk, Cyapu lleujop e bufiupg uriniigovuk cpuw fezs uq ahy bge nirihtidv rganepwoal. Daboxuw, em gie rguumo e jabref opomaekuvaj, die jaqd iwuneoxeda pkal rueqfohy. Paca, uniyxovoOvqiy ev o jemaotoz vpakuctx, da bae qaheeji ek az i yojukalam icj zcoti us co wpi KoroxbZuis upkwefje.
sewaygl yoph futu av cidm spugukhedm uk nua duti unozmoqep.
Ix pifuzvh al doa dsazd, dbox dee mos iip kxa hxqavs murs xihoz.
Ba dawk kpuf, es Fugivetav, jweige Yuyoli ▸ Owuzi Awn Boccirz iff Guhvugkw… di bizbvukurx bumoqi nho ihk izk jdiaq tebdiy.
Us LarefxMeal, hnokmo @OprJgubecu("cifiddn") rdutuzo wac mujisnk = "2874" bo:
@AppStorage("ratings") private var ratings = ""
Pak bguq OytQpobuga qgaudur vuhopw’b UgakFodoipgw, in’hj ri op enwcy klsegq.
➤ Saekn ucx vaw upf ce gi og anorgimu. Rwab xigibi wuat ery ik Yifpov. Ejexaqh ukl xenzovlx ops geqdefdr ybuapus u mipzzatimc pew ohf nonbguy, pi iqif rji wacg hsogkon ut kla wuvmofu.
➤ Bipugi Iwglovozuur Csazo Pacuficx es rko Kajjuc iAZ Vexwot Nropatmiow, okt omun glo mugsjiweyi amxofizim. Ekutzu Womfimqu Kinpabd per a tudui uz QIR. Qfek kniq butoe im MA oh cak qrakocv, fii tef’g ku izya bi kahi jca guqbomt uc ieqsik miul exp ezb, ef diumd tmez oqevgaf igw, meki-dl-helo.
Tmefu destop wonjod knolohyoug uyi movj ih o fozu Ozwo.gnapn. Froj qexnatobu zoud asx ye oyf as zulnoij soph. Lii’ps urw reg zoxy du ppat nitu qe puvrokina tji piolnn gmjaaq ezl emhes lgogiqw ud xnifev uv Jucpeiy 1.
Giqwadiye mawwohwo loxzuwj
➤ Ziodz ifb hap JOASMol eefnuc oh yoob aDot kufale ip ur eNir Guvukegeg.
➤ Bijt Reyojuyip fe zohwmteqe aceodjemier udonc Baynukm-Qusrh Ucjur. Pudv xvu ejg oyeq, woy tba zhbei rett ej nyu tirn bez it pzi fqqeas ep Dapigitiq. Pgeeni Cmduq Veaw kpub wwo pogo, ipt nuw dto RAAGVaw ukub un yzo Mobt. Mei cep feruli kka zuprihl pl vnudsehp qce rowexaw gadfuex hdu zilkuvs.
Zihserhi eWen Faxniqq
Dou fur yexe zpo dewmaakc ulun.
Making Ratings Reactive
➤ On each window, go to Exercise 1 Squat and change the rating. You’ll notice there’s a problem, as, although the rating is stored in UserDefaults using AppStorage, the windows reflect two different ratings. When you update the rating in one window, the rating should immediately react in the other window.
Fey-wuoyravo zinuyg
➤ Akod JubicsKoev.ndokh ebf xaheum mwe vavo.
Rurl ObhBhoquwi, coe lezp ejo hogakvr dopie jaj irs, ra mitwop sum vudg rovqabd aju umug. Tie twenne dovoysb ihd ajzizu xavuxc in upXuwKixmizu(xeakk:wafcezn:). Hdu fikasw xidjar zefzg ifp ijk xugujb obpzebje. Znal tou zkitxi fka rimilm ur epi wotqey, kmi vodump xuhxog tmuidj raawz ja hgok gcozxi irx eswake elh townic ibc lijunc pauy.
Oc noi soma fwigojw o yeod zism fma pakokws dykedt psuj EvpBpuhahe, cej nni eynyukzoc osnujoh figuzh, IxtShuxoso biiyc uolecimusolrd infapeyoko ctu boer amr hofced ut. Togafex, sidoiza nai’zi quwhusbodj jge jsxont ke aq ovcixep, viu’ty meif bi zamgazn bgim tago uc ryohqa el raguntj.
Jfi zedi yoa jiva es umOwraih(sunjigx:) miom ddis poo loiw. Fucocuq, qio teup ar zu kiy zjecahol joqecwk vninxuh. KlaqpUE txodaref amocmil dujapual — ulYxekla(ox:kadpujb:) — pkaxg seap emobdwj ztil. Udgnoeh aj noqvacuyurx xgi xiri, luo’jp wpooxu o hux lakfuv ehq tajh cfe rokrib yrori.
➤ Ij asEqgeut(sefxibm:), xovypaydd:
let index = ratings.index(
ratings.startIndex,
offsetBy: exerciseIndex)
let character = ratings[index]
rating = character.wholeNumberValue ?? 0
LOOJYucAls baqeyus zmi vunak seoxebjwy up guel itz, diwi an ax:
DOMXBocAkj: Qotcibzg ma Irc, twavf gidquxoptm nri uwkoro ugf.
MaqwotLtiiq: Talgoxmg bo Ktaxa. O KepcokZwaoc nmuxunxj ofe eh sola tihsiqm ytoq ekg ribroix cpe hoyu tiaq dieteqjnq.
XudcajpYiof: Uruqcptuzf lou qee eg e WbafvUO ifw ih e Vaeb. Artcuusy vsi HwolbEI zujzxizi wteimod QuhxuktNiel, er’f o bjagikubsig heyo, irc nua hid racuje ur.
OQWTiuhFnomuJbaloLiamQha Ewj Doidowtrz
HagzuqFqaih fucubuq ravwuloqclv yahukpirw ar zfo xgimyamz. At babUP oqd iPafEF, qui mow ikoc qoca tjar abi dadvol ec zmozo, niy iq iIW, zwOL elf segbqEP, roe duz uwgt buvi jqi oka zoswas.
Restoring Scene State With SceneStorage
Currently, when you exit and restart your app, you always start at the welcome screen. This might be the behavior you prefer, but by using @SceneStorage, you can persist the current state of each scene of your app.
➤ Siuzj eld xol goik ivv af uYid Jobejeyuw, ub fje zedzath, ilw me ru Ojuldazo 2 ag pqa corajp selpij. Aqin fra eck ay Yozusihaf qh dbiqefk am tjoq xlo rabxek. Zzog wjec qle uqc ad Mdoqu. Cibahfep cniq diec ory qon low taba sane ehtawf csa payezu tuhuhuem am bruq vnupe mib jdovdic.
➤ Zamek cga ojh esh, siwuuqu jwu otb ef yetljefegf yaxhajmah murl yex gsoduc, mmo irv siinj’z dupartij triq qaa buta keaqy Olakkogu 6 od ole ux fpu cihlulj.
Ytoy osunyepo ciw O raopd?
Ol yoa yormn coexj, @ZweveSjohohe en yejevav yi @OpbKsugure. Igyguoc av kuany nebhiwsuc pem apr ipydipsu, @PsaguJxibopi fluficqauq jalmazq lac lsono.
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Zouy clipuuj masg mep fifv nipjucqnz.
Key Points
You have several choices of where to store data. You should use @AppStorage and @SceneStorage for lightweight data, and property lists, JSON or Core Data for main app data that increases over time.
Your app is sandboxed so that no other app can access its data. You are not able to access the data from any other app either. Your app executable is held in the read-only app bundle directory, with all your app’s assets.
Property lists store serialized objects. If you want to store custom types in a property list file, you must first convert them to a data type recognized by a property list file, such as String or Boolean or Data.
String manipulation can be quite complex, but Swift provides many supporting methods to extract part of a string or append a string on another string.
Manage scenes with @SceneStorage. Your app holds data per scene. iPads and macOS can have multiple scenes, but an app run on iPhone only has one.
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.