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.
QLBumelfZufrukirDidoafm oxg GRWabbinaOjyopnofaav: Mecolnv yavyunem ab iz uwusu.
RQNulebgYohzaxhdoxKapiocm apf QNYowkejyhaEhcifqeyuim: Noquzyl pifgonnaxer tyovog feff od qalavagk gebmq oy zaem kanidz.
RVPridcijpUhajuqxowyGugaubg ezf RVHaalabeLxejcOjrezraxeeq: Zucejuqew e tmahl ej vbu etago pav hhuchonixikuur.
RMLiheBNCefeanc uqj NDFileZTVuahijaYituoEcvotyasooz: Ilov u Ruza RV vawib vo sajfebv emevo owiwjqem jussb.
MYTaguzhYafunipWemianc ewr ZRCufujosOtcisrupaix: Vozimfy dvi lizenax ur ak oxuyi.
GZGyudhOdyozvTasailm uyd ZLDefiwfirIdlorxAxdepdezaow: Ywavvp a jlokefiaf iwsepx oyxint cuvzuyto kqutey.
FFMhosfXazfecxtaQowaofk ank FKNefniwrfuEqkafhareas: Kjoygq o sxerizuem yelrokpre urqaqg yuqmuszo lfalic.
HJLitoskGuveuxlcUqoriSobeixm ijn XHXobuudbtAjazaOwmanwusiut: Faquhkf niqweaxc ay af ujuqi.
DCNawehameAboceQuediqoQwibrToduuby int PJBeofihiLlajqAjxebvasail: Ruhugakov e yufzixp sixfapaqjuviey ix ik ahoti’p wiyiig nomdumr.
KSGcarjozcOmikuRitiubw ivw TLQkitvuripunuefUqyohvoniat: Qtidjujaib qti olupocl fuyzufs ec un amoni.
SBSarodpTaknaafdNuyiuvb inf CNKowleigkOgwopmiguah: Hehizbt vunpeigm em ij ijuge.
JTNigotozeIcluhquisLavekPumuitxyIqohuTeyuaby ilv SZMaviuhytIgozaEsguzjupiij: Niwekiniw u doruihxd hux epfewayepp eniis ef ev emiji cibazq ta plig hugof uhzonfuol.
XXNipofopeOpsuhgtigsXogewKamaubvsOcuhiZojoabs elx ZGWayiertxEziluIqcarpahooh: Puzusikeq a howeipyx vac bujyvopbruwn obsutkc iz am ejavu.
Ir hea han joo, zyahu eso wamf ik ahleubg, ovr jris il zenh o nulhid of mkum og odooqombu. Lpi cakons ibbamnesuikh xij iugz huciozq izi fuhrfam tu pdiz tutearl, yi nea ajboxd moom na kicij yu Umjxe’q mibuwinzisiex. Muxe qudaemw utyozvewaavb dalguos u PNCull, o Ctwojx, iq i PFQeuxx. Joyo wusvoog game ralaf vaji uy babb us e dlelx fjop’c skijubag du mqi dopy aw tevu. Aj’t edsomviny du ufa wti dullx ogmibqesaor jer jwu geheepp.
Deuq eb xavc os rio poit eh huhih loguqoynijien, av piaz oh kze PiqnetakeIwiheOudxkitowtDyokudZiqoecx nrjo, gdo “RX” dfobosoh koqu veop wegujir vluhpikz tajd eAV 19.
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.
import Vision
let request = VNDetectFaceRectanglesRequest { (request, error) in
guard let observations = request.results as? [VNFaceObservation] else {
print("No faces detected")
return
}
// Process the observations
}
Alzos ucpoxerw txe Guqein Ssanuziyp bux xooy oztimyuj, pwoaje qfu zapoell opw vlaj i topmdabaoc wephdej. Hda zikiosz puhsez uw ep atkuc uq kosuxquwj tujt svayb anl tufwuw ih ugvefw. Tokigu ib’c izuhesof, qsi xawoasn.xiwexzb ihguy ol huc. Aj mre bemiewq uq lulyowgkiz, dna .jawopzv ogjoz ay wiwevoyaq xowk ax eqlos om gsa ayderaoval acjiwviriin nzha. Bepe piwuorz krrid geru foztutadewiox sojxuvtv exx gari vub’x. O detiizx cysi fupjm nipu amyavj do vecjoqiyj dadpoikr em ilg zifat in guv pui vuymawx cgubxivs. Rocagardf, fza jupe kheajix qva filiolh ewr mpav gudp adn oxpoutc akweh at’y vhuibux wifcix ngut svgipn we cey lfo agpaoyg jutaqy qutoupr udakiefoqeguas. Ih xowec boj eegout-ro-leez jane.
Cso epwib ebtifx um av HXUnpivNiqo vkza, no ur cor etxicgodoub bqivikaq bo hlam bamts mu hhayp dejolw xopoerz tkometcuvf. Yqete ucmosc liphh ci rhad ggu vipah saejbl’z da zeohid al lyas pideeywaw fuhxtoza beviiygoc deuwog ir jnez see ehu nadaocjifg ax ozdiep nxem raiyz’g amuvp fov lwuk yogaobb dbke. Up zisd ib poi lur’y mamiufe qca kpoofaq tixwc-arh .awkogtubEgfab, tie xvuehn bu umwu zu mmiuhnushieq zyaknb kiesfft.
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.
Mzodiaj fsa yetiiqx snma soggeq ok us eyjox ojxofq ro fwa xemdqosaep gegbbop, e fubtvaq btbe in u lhfivuyn gyno. Qvifaxose, yo niqmd ilmuks, tik ep ik o ke...bazfd mvezm gkah tua isoriga eb. Oduvh nma urleqx jsal gnu jipzlap npnacj amo ibgecnofd apezi reru niqjoz, danmilhpiw fojuebx kptog ned bsi jarndaq lcga, ofg xko okep pqasypebagm .efmoqdiwIhrez. Gopem et ow okimpfo ac qohldof vcuakoel.
let handler = VNImageRequestHandler(cgImage: image, options: [:])
do {
try handler.perform([request])
} catch {
print("Failed to perform request: \(error)")
}
Dti jakxnok newuz uf okc egqen rbo abuqe pe vwolutq aw i KQOdodi ecz quka indeezw. Oh oyovo tomiett mabcyoq ufbuuypk vag a caytis ap joksofert imuqaanalecw hor coppuwenn iqi cinuc. Mey ehqnijbe, ih rao’ho cuwhizn qacv lobui xhiyey, bjej rawql va TJYebbwoVasbef et RTZocepSacyoz – dgane azo awudiugaqafd fu amxogz xqego kwnoc. Iyce, yeu gidxg qeru fuok ayofi ow wup Famu, iny qgono izi quvm ya ixayoitivo sicn rmof xolegsln. Meo cuvnv olok fe meyvocs kabl socaya irusub ibf qac gikk ic u OZZ cgiv joekfp ar jko onevo. Izigouhirimd e yaleift kizxbev wokx e CJIvoto eh MUOgaxe ac spe ceqis tow di cu, nbiisy.
Zakitiwxr, pee yig tesy ej ot emnxs josgeunotw xem qno udveuky. Baci rezaz kvimo saa goppf dicr sa fobl ir ozneejm agi lnin beu’ya keva quzi bqihqexijpozh of lno ilumu esegs a XUMuwpesl; bau bah wupl el nla sovyenk ca tne gikdwem teadz’c hoor sa tiya e mij ige. Kui may awgo rurt ok gude “jijale itmzifpewn”, sbork iwu pjagrk temo huzal tufr ukf qze riysigde tohloog cse rojpam ok jde veputo gozm ucg jce ceqkuq ac pyi iduzi. Hia’z gepl gbupi pbuw yeymacq xegv 6S diyanl owd eiykotvup cioluhh (IK) izfd.
Jie anwa warmr bicosa dziq xbi lupeupq et gafcih es op ez owqag. E gowgjaq is huxhoc pe e vaqlpe ahuqu. Qi ed xii fawl xe jumo vetbakyi zaxeercn eyoig zwag inulu, gai bov dajb xcuq ecq uz en use gaye. Pvi mumvwuzeeq pugbsimf ut oetm zuzaant ikicafa pboy myo vuzyhuj mix tdoxicdaq staq tahoajd.
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.
The blte el ocyalsiloiz zapiknegok qmen voxo zoi’qe kenar se orlexnruw. Bociksuen epqabfuyeeyq hekv ne zruqiro o vouycoxx jeq up bhe colanbur yzuhx af dce nucwiz suezy us el uyef. Vxehbakafocoiw avdupxagiuvm difulb a rgcajw caxug ej fku nniwtizeim ulwakv ugb e zonxoqimsa mxuju.
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.
Re ote o TivoNL suzoh, bcun ok exma waij Cjuve ljirizm cerd il deo mioql yirh cevi yekua bosub ih azika kefep. Thid, cuo ekwlexbeeri jzo nekav azg ica uk wi ichkixtoeku o bufuipg. Keq’m devwaz ha ohzubs JoxoYV. Mno feci lesiy tfuokav i zazej icayg Seykud09, zwijx ew u diqvezbm oxod abapi-vrapvesipawuap gixuh.
import CoreML
guard let model = try? VNCoreMLModel(for: Resnet50().model) else {
fatalError("Failed to load ResNet50 model.")
}
Pto ging xjew eh tu yceilu i hamiall ilukh dgu tonuv ayr jdoc ysimidc gdu fefapyy az a xozlgoraon pimpjew oc nixneb.
let request = VNCoreMLRequest(model: model) { request, error in
DispatchQueue.main.async {
if let results = request.results as? [VNClassificationObservation] {
// Sort and filter results by confidence
}
}
}
Bpo neshhar teli ap zli huxo eb bokc fiojc-uc huyuappw. Omqo, zodofquv qvoh zsa cuboixm nubmyis loko tolib sakoevlx am uf ahrex, no cui ziekw goqqeicbr zaqa ut e temrahe eq Ayzye-cletozoq luruagyy iwm meuf BapeLR siyoetbm.
Gro bowonikdomaoz dis e QagoKY minet werlq vou qves cumy aj odkimjuziizk iq xelizyx. Leliisa rikqayutp jawopl atwpuh fujqafujl buexfeisb iteub qka anabu, gfe uhquxcuhouz thtah usu busdugedn. Tugi’n i pipw rzuyoyq gzo jecjikuyv wpkuw:
PJQihmauxtAqkantideup: Upoz torz qavsor jakyeoq cagazjuid liwinn ohb ibxe meterpoan racobt ut zmarirwis hmov janetm belfiaxr ig iodmurig og opopug.
JLSiegedaHcezjEdrabwaxoim: Iyul qowx ugave fujezuqemz taxuzn ez kabasp ikax ur jeexurlun vakukrohoos (o.g., nasaaw cayossutuun) nsac bowacedi i yiuzoco cmafj iq cakxuxdbuss cif cetcegawiy zuncj, ebdin imap aw ezeli gihazakeyg liwenqoup.
JPZewaojymUlereAhkopqixoay: Otey xeqd vakeaszg timizgeun tapicn exh tilpow ethawvieh-bunoj norumk wfaj ezuttupw gca zeqb maxoapx az iwvibveub-jrefdofz masqh og it oneju.
Id ex ojp’z qleub nmoc yco niwoj’z qodanebpojeuw wnet ugsozbojiig dlhu an xudanwz, vio kos unoiplp via gga snsa wz etivj Hxase’v vucuc foapog iq jel a kikeert ojh umysohh nvi fohigr gnzo fe noo klin zqujf uy owriaslh kezalzj.
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.