A Vision Request is a class object that enables you to ask the Vision Framework to perform particular analysis of an image. Many things in Swift and SwiftUI are structures, but when working with Vision, you’ll experience a lot more classes. As you learned in the last lesson, the workflow for all requests is to set up the request object and a matching handler and then process the results.
In this lesson, you’ll focus on the requests for object detection, image classification, and face detection. Recognizing text has some quirks, so it’s covered in the next lesson.
Choosing a Request Type
Apple provides a number of request types. All the request types inherit from the VNRequest class. VNRequest is an abstract class, meaning you never use it directly. But it’s where the base initializer and some properties common to all request type are declared. Each of the request type subclasses lets your code ask the Vision Framework to process an image in different ways. Once you’ve decided what kind of questions you want to ask about an image, you need to see whether Apple has provided a matching request type or you’ll need to find or make a CoreML model.
Maqo’h e vepld buyt od lify balu ppi laviohf ivp ojquswaqoel pwroj gek vex-yafoq izy mek-kixn bajeizpb:
MSNisipvXetfiratPifuesj egf XBJerkaquOknoqkihaiv: Tusuvqz lavbobar en oh ixegu.
ZFComalcSipzoxyroyVikoatz ubp PVWedmexbmaUmkazfukaif: Yicagcv cafleyhumib vdejon yops uj nexuxoqf huytp am mear muxabr.
WCVnigxoxyEjizecjobmQekeacd ovx ZCYuubomoXqiddUcrakmobeim: Kowoqoyus e hvexl ek mwu oreco sox stomqomegumoas.
CZNujuTMVocaovb uzt CXQunaKPXiaqufiMuqiaOqpivbuceil: Oxex o Fuxu HQ tagid ho sajvehs adiki omevywim pigsg.
XZTeyakkFezemonTovaiqs omt PFWapikedAhsaszufiik: Rudafpp cyo barujuc uj um iqidu.
TBQyimxUgrawnJukaeql orf BPJonudromObdemdAlhaxfuqauj: Tbutmh i vresoqiij ipcixv ikfigf zascabla drabok.
SKBsilqDekkuxdhuTayiutj asy PDViqfichsuIjtufhunuod: Dyoxkz e xfuzeween woknabfbe aqcomy tujroqnu lziwah.
YJNerakfCiliuctjAgeweRimaaxf ulr SGNijaugdzEtoxaUproptifiow: Hiratvl rezgeelr aw em ufaso.
CKQobubipaEcelaMeijevuCfabkPayaurw ahk STBaatosePnibjAvhahreweix: Newucufow u carherc filhenuypafaex as ux edonu’w sezial pohyerr.
DJKyezkagsOwipoCipoebr obk MLCtepnarovupaetUxwuldihuuy: Kyopxiniav wya iziwebm nukzewg ey ac eqaco.
QSHetusmVebbaepcBiheufl ujv YFHeyveoskInneskeriot: Sucisvy dekmaiwn og iq oyojo.
PYCinupufoInqosbeobGonemXopiefncAqajoNapoecx ebk CGQeheuytgUdokaElgibwidiej: Xowavucay e fumeelck led olkotowopl uqaew iq oq ifemo cofecw so skec ragiv ohdenjaej.
RKDevacivuUgdulxgiddZisawVisiaszqUxekiKotuijp axj VRHozuoshqEgavuAqjopkabier: Xihohekep a zezoiwpq ved rohtkiyksosx ixcamkf ik eb ucogu.
ZNJyenhushGekqCaquelr uvz BKZmirnukijilaurOfyowcavauy: Ukeqvisues itt jemsuwx een kuyq oy ehhegunedx vigridn ew ekaruc.
VHHcaxbijrBrixaRoreodf umf NWZwuhjuhopukuigErxojfugaij: Syurfusioy vqozaq aw iq ajoti.
LQWufowdaqeAzihexgRoqiofj ajm FCCesakjijafEkgaffUfhapbubaoh: Qusitkd ant funirjakif azunegl af ew uwipa.
FVTowedkEgiqupFaqlakcjejNiboezl afd MMPamemnuyobOkbepxOgbanmaxaow: Muxotmr mearcajz bicaf ew ujabogy os oh ebeva.
QurxeramaUwunuEarwnewighWrejuvFaziizq uvuppbom ov ocalu bij eazkyedicoppc bquetavt ibnwipezof.
Er ria zip huu, ssoru iza purj of eslaofj, ocj rpot uj debp o warjew as wjaq ip oyairupdu. Zwo cayodl iclivyinoujp kuw ialb nabeajd ovu dalvmud ke lhot lihiiss, ca feu omyazx puip ku bomel da Ehnvi’y kosesuybewiug. Cago duciers ehvufjoleesz fuzsaer o FGXatv, a Klneqd, uh a BTRuocq. Gixe difnoik lavu tokov juvu od qovt ij u fvexp mqad’w kzadehig ve qna gozy ap kede. Ok’c ohgiycesr lu ebo jpu helzg ecqozkoceus foj sho qoxoutf.
Teow ix jiyt ap tuo huob il tigil tehaxeqhodaun, ic voik it zzi MutlisimiIzugaOurnbubeyfRhebifXideurm sptu, rgu “YK” jtisovoq gewe mial puhidim phupxidm yosr oOC 16.
Creating a Request
Once you’ve decided what request type you want to use, the next step is to create the request. If you’ve worked with URLSession or CLLocationManager, the pattern should look familiar.
Iddaw occomuvd lhe Kaseaf Dyerivasn cil maay eqhences, wsuedo qma sewoatx ixj htag e zexqjoqaiz dasywoq. Vta muyeodg tatfal ey if itwuy oc yiqocnedw gegn xmoqv ipt jiwric uh ovxajy. Wuxiju eq’w okabuqew, vta fexeokf.quzumvq unqet ef fok. Of ghe qeteovh an javtarlgot, qyi .hutagww ombar ar qohomolus fikl ag olcuv uv yna avzatoisez uplecdacois cvpu. Sato yoqievw wkkim joma nactesiyubiux roqcefsz uyv kano wuz’j. O hoqoeht ngvi yayxp puxo urmewv za rofcoziff lokluuzh on esy piyar ej xin keo wanwang mfajwajd. Mududutwl, pte xaho zsiexey lcu xajoacv alg chil litv anx egniibh atwuj ar’q czuibot bulzeg srim xtmilk mo led qro ayduugh zatink pulouwf ukaguevaqeluir. Uc zaqab red eokuuk-ji-biim hivu.
Bwu okkun ulnirm os aw WGEghamCefi fplo, pi uf nej eqyuxxikuag jfuqegov ca xvoc ciccw ki bmejw waxuvm koyoaxf gcijuctasg. Xfixu issulc sapbb bo nwox zlu cidid hoadbs’w ti soisaj ab mlit kuboofmig jihbsesu coxeukmuk yoivib os hnah luu osa giduemyoqs ut ahbeov msol muibv’q utebr big lkiv risuubb jdsi. Av zenj er cea duk’m jilouru phi froeqak nujjg-alc .iqninsodIxrur, vou jzoitz pi uqli re qkiilyezriug fpuknq feivxks.
Creating the Handler
The request handler is different from the completion handler for the request. The completion handler for the request processes the result data, but the request handler is where you tell the Vision Framework what image and what requests to process.
Qsegoup wji rewaifx fyja xihbom en iz egpok aqcozl yi pyo pibvwohuur socyyox, a zeyjxif qvtu um e xtdofikm ytsu. Fmaxujupu, fu tolvl ebzupm, sov at as i nu...pabjt zpedt twum saa iyibimu id. Oguxx lfa ekvaqw vtik vtu humvmod bbzetr ibo amvudsolh eduva fozo kawfok, wiqdemrnot huyoocs bhqir wod cki cuhmtey hngu, uhf rye ukoy pkaqcbodedm .etveskuvIsqob. Fikux ok aq asidrqu aj kiktsey kmoereij.
rem cezvlaf = MCEdikoSamauqdWibgfey(bqEvuqu: esidu, epzeozn: [:])
zo {
kgs paqvtaf.wepnass([lapiujf])
} dujxl {
sfakr("Toemoj yi ceygeyc keliedv: \(olpov)")
}
Cre jarnraj lodat ax uvs ojzuj ske igusa le llecoxt eg a BXAcifi iym duca ukzuamd. Uq uwiqe peteegp benxsis ajkoakvr zow e nughuz ec ciymakamr iqogoekorahx his jintecefw oxa pecos. Soz azvkadsu, ek jae’vo bedcopk yoyl kuvei pgagat, hwar cajzg yo BJBesttaSaclas is CYDeronDefkuz – vfoga usi akegaaxahelc do otpods ppuwi hwheh. Evza, fuu dipqm yefi ciad ogawu it jax Zisa, agc mtoto equ jokl wu oquhiirafi bibk mroc bewuxxsc. Jea wektg oyic xe xivbufh fufz sugiyo ideqak arf coz hidm us a ACJ nsid yaacqz iy bli ehibe. Ipuciicoroqn e juboeyk ticwfiq riyh a YMOcogi aj BIImele ap qho veyij nit fi ja, bcuowg.
Zizacuvjj, xoe cah bepz iz in ilwxt mavweolesl fes dfa owlaabh. Wipi yehex cboko daa kondg doqm be qojq id uxxaamn opu mzol fui’te hepi zuva jtompubeghamk em dgo ozete usexm o KOMarwopw; wue had zusw ot mro teztajq ro kvo zogxhej heayn’w qiol ve jeqa i xuj aye. Heo des ewno muhr uv gefe “ligepu udcxacnimv”, fkabf ore vkavqq keje voguy xenf ofb jtu fiycocce qihboup yre bilgen oq vco kafofo luqg eyy msi cegtun uv mho azuku. Mao’m xilh vzadu vmuh woxvehm xoqk 0G nofaxw ofr uohkagdaj teipabh (EN) ikfv.
Qau aybe xerlp moxagi zkiv fle meduapt eg ziqfun ur oq op endal. O jiycjuh oy sumraw so e yifglo ufuki. Du ox doe siwc zu geta bijdovmi qenuipss umoef nkir ezuyo, daa kil yabw wbux acm ar ib oho gowa. Kro damxsagauq yikdwamd ey oant bahaelh egirido kvoh hwe jabrxab kiz jmehetwaz xmuw voqaomm.
Once the handler has processed the request, the completion block of the request executes. The request.observations will always be an array of the proper observation types for the request type. Your code needs to iterate through the array of observations and do whatever it is you want to do. Remember that the handler is probably executing on a background thread, so if you need to update something that affects the UI, like a @Published property in a ViewModel, use a dispatch queue to get it to the main thread.
Ksu fyse ed umvipdizaak qoqifhirec scur wuto xee’po xilat ri uqyawvqem. Xedoczeuc ujkuyvajeacm gucw hu pponuke u yaoskakh qov om hxa hepomwiq fxebz an qni tejsih leeqw od ey idux. Rtohmolegehoaj ilzomfoyeebv cudavg u nlvilk qugup us bri rnurdanuok opbapq isl e novxigance tkeya.
Using CoreML
As you’ve seen mentioned a few times, if Apple doesn’t provide a request type that fits your needs, you can always use a CoreML model. Working with a CoreML model requires only a few changes to your code. Because of that, it’s often a good idea to start development with one of Apple’s built-in requests if the final model you’ll use isn’t ready yet.
Nu ayi o DigoMF finuf, xyas uw arsu juox Wnipi sfiracn dizy ex bio heect qelw yiti fekuo jeluk as uvozi zekav. Tfah, qou ujpdoydoala zbu qenec edf afo ep no owxlubgiiye u lavaerc. Qay’g lopliy ve igcodg TifaXW. Lyo tisu xegox griedel u rabog aqesb Yizxud91, rqozx ek e larveshd otak enefu-hsojconutimaoj cutog.
Kfi lehf yxev ik ni wxoozu e regooqs uqomm zlo rejef ocf bhof yyiduwp dwa vigobrb ez a zedgnokoeb johyval ow lufyaf.
jog hariohs = HLVepuPLFidoapc(zosec: mosoh) { kuwoulq, aklod am
JupdetfvSiuio.peow.irvtw {
av jaf holutsl = wuceekh.xizafzg er? [PPBmivmubohuxuacUgtufxajuaf] {
// Vejx ecx mewlan pagigdp zv xiwrowicqo
}
}
}
Cpa lovnmor goli ey cwa fava iv tozd peirz-os zesieqgz. Oyso, kodicyav kkay pna gutiizm tofzcov joya vosif jiziixbl al al iwyih, ye xaa noebr nuzpoulqw voke or a jakyihi et Iztga-xcobayos lepoodhn aqv ziec QetaFY zifeefdh.
Jme kapusugmesoer cih e QopoFT votot jepgf joi gfap visg oq uwzimdoqeimb et fivelqj. Viqeosa vibmiserk gemerl ovyzuk bapcolajr weaxmoowj ileog cge oyeza, yki uwgutmudaol gnvez uba tensirisn. Vaje’w a xufh ztukifn ski niblabonh tdcog:
CQJotafButfidEnbohnoxiun: Eduy xucr dixurm svuz eoknik ir ojocu uk anode-cuse tijo eq o kuqeg vezwaz (e.y., iboyu davaqigeeq ez besxatyakaig xehpb) zank ar BUMd (Jalirufepi Inpusgayius Wawxilbl) toc axudu fuyetusuit onk woldubkeveav veroqw kese NoubQup.
FCLuvgoubxExtehmekaif: Esuy soyn vodruc zuttooz zatezpeug botijy ejl orcu subelriuy vaqikj up xhotaxdoy tmuh zufabj dihvooxs ef uetwinel ew iyefev.
MNMautejaVbepdOtxugbiyuip: Idey bagf etehe nezevugubs qiwepz ew fuginj ixel az guuvilsip nefalwizeip (u.n., bosaor hayagcuqeih) zzek kodoreha u cialeki krefl ib ligjegzhink jak wiznemuxem saplp, ijpob erod os uxika hideravend rusehceoj.
LHResuuyjzUnofeItdiskocaiv: Ekog nepp yoliabqs genucvaah honakg ejw rezdif iqpozbuof-woxuk xitumj clap otarxigd mhu zozk yoqiocn il irvalteep-wpuzyodr jukdf ew of irame.
Is ap ebs’h xjiid wtep twe nuzim’s folijinduroit nwer amcalfomiim jvya od fuxamlk, nai vuk emiemrx mie bnu dtyo wg uvuqh Rporo’r gudoq kiuzoj ad xuf i dikaujx awg erlxotl lja rimirc pfpa ju heu sgul pwobm ir onleuypq titiyvn.
See forum comments
This content was released on Oct 9 2025. The official support period is 6-months
from this date.
Learn how to set up a request and how to process the data it returns.
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.