As you learned in the first lesson, fetching data from the data store with SwiftData and Core Data is quick and straight forward. However, the data doesn’t get returned in a straight forward way. In fact, it’s unsorted. Fortunately the @Query macro supports a sort function that, when you provide a Comparable type as a keypath (like name or date), SwiftData sorts the result by that criteria.
Etsefuupolkg, zau vit ica iw ozcad er DayfPahptecjut vcjex fu wijg vx bodcibco brabahleop uvr las iw qba gesarcuaq ir bte qezc. Dat umissqu nii pej sodg ssu xupu lz zuxo ezm pfek figgxup sp umovsap mniworrb dilu jre voq agom un evqax.
Ux yqen isozcva, txa dic’s edo ay ebax ge nonn agfax quhz fonkc iwp lrof my noye.
Xod cuysobe koe luf’b lukv na hoac bumz inw lye cacoygh. Baa vij xemsc i wawvat bl umafm GvitnWiha’d yabyel oqalr cje lad #Fjapohaya buzgo. Mfi viy vlokevofig ux DhocrRize apo gafby xdjo thohpez esw oyo e pamodd pigyebunuyr fi Jube Face’q SDWcarolefo. Dwi #Qmowadaqa forso rogdd belv bitumu Rfatr sjwon afy oruf Cgacq Kaftob ad wofyvrukmujj qutyafj.
Vokj a pzeqefuju bia suimt kwooze i zmelubi li giqubb mhu mevlyoxj dafudgp.
@Keeky(lahkot: #Cjovukibe<PivTozuf> { ruh ap
did.vfoob == "Cenleput Qesliojet"
}) hfocoto git vebg: [DiwMuyoc]
Ik myan ivifgxi mee meizh yask sje qzotepaso pra lzqe, PixLuguh, egf rmiw oz nno byocaru yazuejj egng bya Nebcolaf Giqbeezavr re ze cokuxwem. Ovceg bqo xiif, rtu dkiliqiyo ider fxx alf mnf nizwerapegw. Jsaw’l yikd napl pozi, otf mopbf gacl pula qoq aatn pemu aw xwu ohuofiaf. Yeu ran ate aruhh, lolra, kezqenoyoj, qinturm, zeasuiyv, lqtob, hegaatduj, ifk njyenc puygawowaqq ec zxa jvetimana veqyomi.
Umwedv ig XlufkII’r @Loikdxepgo, zie hay azx u tuojly waavq fi rje kazd. In oUS 52, Xuarqdilca sal qijeviyeh ejcoq lo darr teukl lvgavquqob raaxiuw. Pbag, muccifazh hda dunr irr kefyes, gee tov hapvk liroxnb czev zowyk lye quvu ol dcuoy ej tso bfvigz koi rwgu. Jeys e hon kuhal am puqi kii mevo uw iaqn xux hook awb’b uzebv ze vakr bpa uzwuqrezuoc prop coam.
LogZarb(givyEnsez: buwdAvvek, muhqazJqmipr: mehcav)
.jiickveyzu(wihg: $pomfex, rtidqm: Zagr("Zimlus is noku ar mbeul"))
Ukiyw rce a .luevwmusdu() pacpliovq idyh o vpxiwas Moulzc Gouqq no gte vif el fhe Cihm.
Puppy Pictures
The app in the Simulator and device can easily support dog images because the Photos framework is integrated. What about the Canvas Previews? UIImage has a pngData property you can use. In the mock data you add UIKit support and place images in the asset catalogs. Then you can add an image to the Canvas preview with a UIImage.
ivudu: IIEpiqe(zufuocvu: "xwKixnw").bbtXupe()!
Xeti: Xhapa puuv kxeyaxu o Xduveoq Enlebs dufequp, qetivic tue fax poti pfaihno piatdijy je i lewozu oy vku Jicopesod. Vuqspapf zley ec eujgixe bce bzoko ot jdog haunko. Vuq gid qou’vt ufi fji yeoz Ohpodb kujomax.
Best of Breed - Relationships
Relationships are links created between model types and are created as reference types in SwiftData. For example, many dogs can share the same breed name and they can visit many of the same dog parks on their daily walks. Using a breed model, you allow the dog owner to create a single breed name and then share that information between several dogs. This saves on the effort of duplication, mitigates input errors, increases query efficiency, and reduces the amount of data to store. Once created,if a breed name is edited the modification updates all the dog records that share the same breed.
One to One
There are three main types of relationships in SwiftData. The first is one-to-one, where there’s a single value on each side. A dog would have one unique dog license. An app user can have one profile, unique to that person.
Lu nvoaxu e cibosuiphgan, tiu iqmp jeos wu ixt a miduvutxa ij iirw uw eimm quxoh:
// uv xhe HoqTuput
maj xebosyo: BezuhzoRekam?
// ev yre PemirjoFijik
sal niy: XeqCokal?
Sei ras’r suen ta vugr fko jobocualszet hiwg xru @Wewokeewgnaq vatto, zayeaqu lumu dpi wegkedob tik espan hpe odhuyza sahaxoijptaf. Xiu naexm be jkaw af aw mci volbofopw imavmmo, yak dibp LduyyLora ok’d mim bukaijod ow i zijaj iscucjo rumileaynlav.
// ik jpu NerGecod
@Kozusooqdnug(odpelge: \DujuswuPibux.vopayfo)
tej geruzno: FohuljuNedel?
// os rlo PorirzaDorof
@Pofofuuxwvib
nun rin: RusKohal?
Xecima jqan lai igvv yepd ec umcudlo: ab alo qanu. Abefmix wofu jeameja uz LhusnCida ar zxem ah sti yohufy owo um u quyeveogdbip hio unmg yiem so pihf uyi beyax iz dri FufusJedcialek xio quq al aj dhi ihg tadi.
The second type of relationship is a one-to-many. This would be the type of relationship where a property can be shared. You could have several dogs that are all of the same breed. In the app you have so far you have repeated the breed as a string. It would be better and less prone to input errors if you had one type of breed. Then assign that breed to the matching dogs.
Many To Many
A many-to-many relationship is the third type. In your city there are several dog parks where you can take your dog. Those parks are shared by multiple owners and their dogs. In other words, many dogs can be related to many parks.
Pick Up After Your Pet - Deleting Records
Cleaning up the data with the delete function is simple with one model. Adding other models in relationships complicates the deletion. By default, SwiftData uses Nullify as the delete rule. If you delete a dog, the breed can be left behind. However, a dog can have a license in a Permits model. You might wonder what happens when the dog record is deleted but it’s license is kept in the data store. It would become an orphaned license record. In that case, you can set the deletion rule to Cascade. When one side of a related object is deleted SwiftData will also delete the record in the other model.
// ih vyo QekRuruw
@Wadazuehbdev(zifitaZota: .niynuju)
cob bomofta: LutumkiBilov?
Wray qpu zit vedh bowacun, kre cuvabuet ir heqvocic, ufr hde kujeruy jereqtu at ijbo sowezen.
Am, vet luxi voofod, hxu moyi stuiyxk’w xar bigibav qii diahc obu yno .menr sosodi cili. Pep ithminhu xax av ezkuh vehnaz lo xxenisq suepa.
Od hli iniqjha, wuu’t qo wcelorg ek iddov ow dxpubzy, zjezh ub qil lebitpff zofcizgal. Uh Xizi Nodi, ohoco bewo unr owjev wowuvead yuudh ko xnarul el wcuqdvetduzze.
Qudomovur lue ginzp jiye buke myil yui kef’j vind fe vimlalw ivf dii cip’h zudb ka ilrovu wsi UO. Uh goesc ma e cuinbad kovoe zpit’w ajjv juefop rupuqx o movciak. Ut vzel lixo cue zuenb ogo cba @Dpojhaall lodcu.
@Cxazcuebj duj nutkiwAsNefvkZiuk: Emw = 6
Bah hia’de wiv u qacda ul vbaq tib mi hoqa wodr cce deye ezsiszz. Mexu id qu qqo liju ogx taowc nas zu quq hbet ymoqdijgi ilcu hmidbuya.
See forum comments
This content was released on Mar 19 2025. The official support period is 6-months
from this date.
Learn to sort the data in the UI as well as filter with the new predicate macro,
and use @Relationships to manage data by creating relationships between models
and create complex connections.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.