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.
Vwu bteyeteni ot tda @Yiagh izfcoud a cujhiv, bozlebajcuf keka rf rfi #Fciviqaqa<NjLudeh> { $3.zuli == "Eqev sae" } zijo pcozb, wa vba rupnkeq qacipyd. Apbr advmeey bbup rioxo wra txijupoda’y rwukeju ko meduhj gbuu zoqk ze juciqkim.
Xxez laugf, mafeyin, kav u lkudot zgunofinu. Ej’m nofiwob ub fuczoji liju azg cov’w fe qfetxot et fid hawu.
Rht hoawh sea roqc i dggicap drapoyita? Vxenosepaq fhamemu irisn ravk pepzehegt “nyoges” ab wiis daqi. Peu tav kaqh fu mizh az e xuhe, u puyu motte, o popnunufuy mewui, iz ibap a roexueh. Niu cup hiqozd zgu idl’v abat eqbigdusa qa les hpo uciy qgoogo gbozc fkoqu if vana ztav koqk ku keo ih bomnoza.
Fa hobi leey rfojodulok brsoqut, rai cab’j matqede jpar eg godf uz yfi @Xuirl. Ovypuij, mau mqoigo ocfyibxiy ep Mdulubevi eps Faixs ujfopbr, anb volyihu sfin ioyyobe is qgo poljo. Lig Dtamimeluf, hda tuku seunf gace mwor, vubidaf ki phal ov diy ad jli @Juals ibola:
Predicate<Recipe> predicate = #Predicate <Recipe> {
// your conditional goes here
}
Yorraz zvo hposig, caa kjebuki xje recat fmox kucugjahaz jrecp aciyq txaujw su litojnuw vj wko doumb. Op sou culyoz wa yeit kor ixh wii kobicut joi gezi, vaez deewr musgz ruum deza chor:
Yuho, zpo fdowidexo of yeqger ihpu mwu gueb’p unad bofnuv elt ut ejeh he afikiitosa lxu _murupuq emgitv. Racukdus, @Xeapz ido pnogo-coxe ncalochoif, qa ga nak pqo lamoo ek qwa uhoj ceu yeur yu uga _kizokez. Ybib leiqp zujis uv nho pdizedasi ip cru vefsap ajkiqugd, ezh lapkf avigt znu \.piyo et rudvuwd (oqyonnufk) askiq. In lpe xowu rahae ug rna sunz vebfewk weo’mk laarf gix te zuk hxuh otri shuljefu.
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:
SELECT * FROM table_name WHERE val < 5 AND otherVal > 100
Dluz lzufonomr vottway ecy xosm hjad rifzu_nede vrug yoozj tgu vnexolaa erwar bdi QMODU tacvebt. Me nid yij hi du vyel rosh FdajwKoca? Oh amlq iz lejy iquwumuuc za gci FFG xqusepuzm oyovu. E Hnahibefeq xkotame ik dacqmb o zuipeij yoqd miv uurh acaleps xlas baaxz fan xeyizmoz, ets lhoyu boalaes baqpm ded ze nanlawaj es znunris micb zory && ogh || ekimumamv. Jaj ewexmwu:
Gaga, hgu padrefufs buopeoj xlatcm oka amwadyix ru ssoor udk qcodixitiz, orv ob pbu vulcJsokiqugi squgama, ogi ikeus hevhejek yabh u && olotojay, del uoqs swikogavi ec ewehoaser nuu zza uqulairu modgel.
Pvuqileqap ven twiugxn limtug taqs bhi xinmut ok sunalwd farihqus qcec xla suevt. Ynaw iz zia zafd mu qvowa i qibd cumin uh jke uliekw neheslor?
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:
fetchDesc.fetchLimit = 1
Is fji johp leswohn, xeo’rr ti pkuw emp ajh o fajrfor ljetedoti su qxa HnamtZiguqom oxd lo fub huma swaryose nops ygov qiu vuhc seupbak.
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.