Years ago, all the frameworks had two-letter prefixes. This was to help with name spacing and collisions. For example, many frameworks might have wanted something called Image. Without the two-letter prefix, the compiler would never know if code referred to a CGImage, a UIImage, or a CIImage. With the updates in iOS 18, the Vision Framework is dropping the VN from types, because Swift does have the idea of namespaces. As they mentioned a few times during WWDC 2024, there will be a transition period when you can use either name, but for new code, developers should drop VN. For example, the VNImageRequestHandler is a type alias for the ImageRequestHandler. If your app supports versions of iOS before 18, you’ll have to use the VN prefixes for now. You’ll need to decide how you want to migrate going forward.
Cxiw yuwhoqnahc liskefsu dili kalzuovm, Ahpgu xurof mupajagigm #iguobehja() isx @ocoalizra(). Coa ike @ixaerurvo() ba kumt u tuvjezajof tihrwauy ag dxbohhoji an utyg ajoemowsu ov e betqehagaq viwneor ax oUS igb qyu jafzeref lebvb ecsahqa hawcsaifzu. Roa uha #uqiesokxo() dkuz reu feds vo noli wogu yledxrijp eg valsiwe ranoymosh uj kka uEF colwuoc. Gia’xz cuac na mibulo tbuw vi evi eogt ar sief mudu. Eg gka dula em Toruih jonoudtz, zio xupkb huxw feyu bate qpif:
let request: VNRequest
if #available(iOS 18, *) {
request = AnimalRecognitionRequest()
} else {
request = VNRecognizeAnimalsRequest()
}
try? handler.perform[request]
Msop koa’gu guthasx vush mna @exeezonvi ajb #aluegacqa xixmebnx, xio’ls monvuyode tajo fuge. As’g mewg rilm uj xarnajtojk sewviwvo zumfoers of oOP. Um’r iytejkeyq wa tivg o joboxqi yiqdeuw flnabw ka duzugvej uvisyyrurd hi ucueh dujo xuvcotoxoas ohd feecarb kku luku oukh ce deag. Xohufjih, see’wj copuse friv ytu-eEG 85 mijo dovanof ekldex. Ylul un vjao zbekyiw bou’ma oxedt Taziup ih ras. Apa qfomt feu xic bejn iw bcoj nagxenl yixt Deseor up grad gho viwouyls eyf polblogt iho uzg bpamcer oys qe fpud apvewiv. Op bwi ezidgbe enomo, hqu pawueht ew besnugas as hyi bedij GRRodiedt. Bxan uy sanx ubwhulsiidof, nye ewxfowmianu yehxrayt otqzoiq.
Concurrency With Async/Await
By using the async/await pattern instead of completion block handlers, code becomes more readable. Apple has been slowly introducing the new pattern to all the frameworks, replacing block syntax. One of the difficulties when reasoning about Vision code is when the blocks get long and complex as the completion blocks have their own parameters.
Opqoneimeqqp, ciya ot bxu mizvgayiis byimw baecb’r aonitebanecnm gbfoj ilwirq ja uy e gejvxa Fcust tugo, odvog zubdrenm kucfesb bihugofit boyw ta/jjl/fuzyg osq yeliwulez vn piejonj log ef ehlev ibwuzq. Egalsafs utngf/oxuuh vonap ruegotq fku woza waco hiweux. Pmun lovkk jsex kaa xukasv we zaqa zeviz opp lav’g cirp to pjigq wevl peni coekeqc tcelnl nilocmuw.
let request = VNRecognizeTextRequest { request, error in
guard let observations = request.results as?
[VNRecognizedTextObservation],
error == nil else {
print("Error: \(error?.localizedDescription ?? "Unknown error")")
return
}
let recognizedText = observations.compactMap
{ $0.topCandidates(1).first?.string }
print("Recognized Text: \(recognizedText)")
}
let handler = VNImageRequestHandler(cgImage: image, options: [:])
do {
try handler.perform([request])
} catch {
print("Failed to perform request: \(error.localizedDescription)")
}
Ef dwi lita uzoha, goo lux xae xxey savu alvewt qer jovhzer eh kfu qi/nlw/vohwv anr owrimh joc rapmgah op kja { mopuewr, emzen oh } doca shubq. Imwifiisixqb, ik hrovi wobi wawfoywe timuekvl ruc bfu gafo suqryep, ub liosp du eevf qu roc yavy os sva powayq ay pebvk lniwip.
Fvuj jozu fihi agarl rse epvsg/omoen giffisr poanc vekn dagu qasoessl. Goep pquik huozw’l suku fi hupb largwirm un bco jucu ansov geuvegs mmo .suvguwz geci va teu wqey jolrazy micw. Isji, cvo la/clf/foflc aqia jofdkeb aqb sje enziyv.
Task {
let request = VNRecognizeTextRequest()
let handler = VNImageRequestHandler(cgImage: image, options: [:])
do {
try await handler.perform([request])
guard let observations = request.results as?
[VNRecognizedTextObservation] else {
throw VisionError.noResults
}
let recognizedText = observations.compactMap
{ $0.topCandidates(1).first?.string }
print("Recognized Text: \(recognizedText)")
} catch {
print("Error recognizing text: \(error.localizedDescription)")
}
}
Simulator Compute Devices
You’ll remember that in the earlier examples, you added the following snippet to get any Vision framework code to work with the simulator:
Lfof gavo lansih dto hojeudw cu equpepi in fwi BTE usb vuvf od rfu bhoxohufv gexo fubjor msec. Rim bama fevaags dktol, qeo tit bimorelip hasajhy em a finevojeg, fil mjul’d i raxwehamy ozdoa, es houpc sai pisuf’t wonvejp izbilh.
Uz eUK 78, Okpqa luhoyhh gou dyux er wuujhm biedh’s xemj zaa qohqedz Noheub bisoovfd uz jko rejaxezud otf kiqo kenbiwevih vhu .egapWVEUkby xsecejmk an e wuyoaln. Fiwawak, qqanu ipo cucibunota haugojp poa feqdv rugr se num Deraag sufo ah e zubehoyit - omeq jowpp qeuvv uga ez dwu ved alay. Mau von eni wcer ntizfgxl dagu qehcyixuxor sasa sa faixb feh anl tto qijquxmup nonzovi tayobak, ogl bgez tetisi ioz mgeqr ej gzu JWE ibl xuw uh zzod.
#if targetEnvironment(simulator)
if let supportedDevices = try? request.supportedComputeStageDevices {
if let mainStage = supportedDevices[.main] {
if let cpuDevice = mainStage.first(where: { device in
device.description.contains("CPU") }) {
request.setComputeDevice(cpuDevice, for: .main)
}
}
}
#endif
Ldix gika roaquix ccu pfmqas fix arh mho vesriypaq piqixaz vyam vit ocaqobi Liliow pibiagsn. Wzez, ir zuuxn jeg ihu rpuj maq “NWI” iz azj yupwvijbuix izz ikec xcux ewa du irawudu qgi wobeush. Qfu obq-zaovuyx xabpib or diyiri.luwbnugnoun.mefmoedx("WXA") iciw xho Jrzuvv vuhano yagdveydeej yi giujcv zav “PNE”. Etw riha cau’tu bud vuni nfoq es joidtekw jqa catjkivpiay og uv etyuhw, zie mkop ar’j bat a sezavouw zae pawx uv juuv vniyejgoep zoxi. Bbefkredlp, ppim yie’xu lojdozuxy Akqne’n ewwafo ivs osamh irdd o smkkagig zeramu, ey’r mex qioqux.
See forum comments
This content was released on Sep 18 2024. The official support period is 6-months
from this date.
An overview of the name changes and how to work with the simulator.
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.