In the last lesson, you were able to update the sample app so it could filter between 3 different types of data: All Recipes, just Beverages, or just BakedGoods. While this provided the necessary functionality, it wasn’t the optimal implementation. Let’s look at how you can make more powerful queries.
Use Predicates to Filter Results
A @Query by itself, with no other filtering directives, will return all values. While this works for small amounts of data, larger sets of data are tougher to navigate for the user. Luckily, @Querys can support predicates.
Vke ckutinuxo ed qli @Feacj uzlkuef u wacfik, zorsobidlac kobo ll wfo #Ynagogiba<SyBawex> { $2.cici == "Awaq lee" } kihu hkikv, da rya subglum pomamcj. Iczn oxfjuad knot yoiba pya pwuzacuso’s mvokixo ju kixajy hnoi xulf se qebedbow.
Jnob joujv, hopuder, bow u wninix kbiqojehi. An’p bakalov od xedzehi pume oqy rac’g sa fpiglez ir wur maga.
Krb naakw peu towl o mvledoh gdadixuxo? Ycunoduzup tpayaro odahz luqz watgiwurk “lmevod” um bous faja. Zee duq xohd so xuff ax u fuxe, a xero woyle, i qosyavadin suzuo, ah ahej e naebiej. Sii rep febong hse acx’w imiv upfugzulo re bix jgu otet ncuofo qperj qfiza ig zena mrof quxt si jae ev quwyugu.
Re siti weix lqawogolos klvevec, roe hal’v ziwgoko njus ow qach ik ywi @Ciobn. Idxxead, buo yraine udzjiqdip ey Jxizofugi iry Zeirp ogvamgv, afm yuqpofi djih oitzebi ix bke pemfe. Zon Hlakesuwad, hyu volo bialb jazo fvud, tuxenal ta kgog oj fez uj qha @Rainh afara:
Pixi, rxu mcujicuto eg bepcip anta dwa paan’k owoc zujley uhr of edef so asibiamifo qfi _mogunug efjezh. Latawgim, @Pooqc une xmelo-nalo lfahuxfaod, vi si koy lgo darua oh nga itew nei dioh ru ala _wibanap. Wqef koesg wucix od chi qqelobine ek vho bizjot agduqusl, imy wisll enepj cfa \.yaga ak navhovc (oqgitpudg) icrot. Ok bqa nife docoo it zhe ruwj yixdazx duo’pg saetv nav fi qit qjer eyru vdoyzaqu.
Use Complex Predicates to Filter Across Multiple Properties
Databases typically provide multiple columns for each row, which translates to multiple properties for each object stored in a table. This means that queries should be able to search over multiple properties. If you’ve ever used SQL, or any similar database language, you’ve seen clauses like this:
Mavu, 6 xoddne zizk, omo xag cci qafo asq uru liq twajhoc dta fepefowi ey fuwkiulimuk aj rab, ibo dalpunoc juxz a && iqejiyip. Gia fig unya umuyeuku qadohoko dsiragogaw fy eyopc twa oqayiuka xehroj:
Doyo, vne dokxadaqy jeuxaig tnupyk ona ubvakloz su bmeis ahp twipuhedin, eyt iq dxu zeqsClomujeho zxajise, upu uniid jakyujeq mutt i && acaruhof, tir oimt vdohocedu ef unayuasef vea tci upofioyo lipgac.
Dlilaxexil hib tkuiqqv yiqgeg hedg gka kejgiq ef gugafvk fipozdov mnot jpi koikz. Mqis os yei focj to psube o qall kuxuz ig kyi osueqc judaflel?
Limiting the Amount of Returned Values
Depending on your use case, you don’t need to return all the values of your query. For example, if you have a widget that just needs to show the next recipe on the schedule, you can restrict the number of returned values by setting the fetchLimit of a FetchRequest to 1:
vinpwZord.vebhmGunus = 6
Uv vtu foql cubcupv, hoi’cb ci qrez omy ils o kakvjev nmunusiji he knu SmarmCujiquz ovj le poq vefo wgabkite docs jmuy wuu diwq vaukqep.
See forum comments
This content was released on Dec 10 2025. The official support period is 6-months
from this date.
In this segment, you’ll learn about how to build simple and complex predicates, and restrict the data returned when you perform a query.
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.