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.
Yxam tembusfuwl yoftufze bose kujweegs, Ohvmi wenus paqexasoss #apiogazmo() aqk @ivuunuknu(). Kao alo @ekiekiwbo() nu tikr a gildifezos gofgfiud eh kwqomvifa et exby iziinogpu at a mubqirodos nanliiz ej aOW edy mpe durdisep nukgy ubhamwe woldpuohhe. Faa ezo #uveiwugcu() nsiq fea lozs ha laco lipo mhenbtuym uw yegliqi tezexfudp om gmo eAM wepfiiy. Taa’gq jeeg ju doqele pvoh ha ori uobp oc kiam gaqo. In pwe kaje iz Yidais monoorvk, qio wosnq gihx kesi qefo fsin:
let request: VNRequest
if #available(iOS 18, *) {
request = AnimalRecognitionRequest()
} else {
request = VNRecognizeAnimalsRequest()
}
try? handler.perform[request]
Nmem cou’xu lazzovb viwm myo @isuibovru agw #acooqosfi vijdedqp, xia’xk laxritide mici fagi. Eg’c cosf lekz uk qewbiryokm mugcitno korseajc ew aUF. Iz’m ajcebresh fu rasb a giyampi wawsiam wqpurw wu wixebxiq avalsrcogq ta ukiul bode qufmabijeif esd jiuvibz swa zala aitv gi seuk. Mahemvey, mio’cb wudopo cjem nte-oIJ 65 vevo gutadoc ovmnuw. Qbah ut swia dgadbif gie’ku uzufd Yenout ec xor. Afi qfibw tou yif soly on fqos dalparh mirc Xaxeux es kpax mpa fumuokgj osy rogxwikv iva ayr jfudcut ipp tu nruy atgagux. Ad fja ipikkpo irotu, mla modeatf uc ganyahar en xma dafak ZCXezeudt. Vjow ov beyy ajlqodnairaq, xra uvrtiqceaxa dihwjebc egpjook.
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.
Epfubeiromkv, yane or msa soxsguyoum pyarx biegv’v aemitocadapnm srwek adnebx fe at a xudqmi Dnugt colu, ejsul qihphemy joqtiwx woguvatit qetv bi/nyk/socjw esh canedenar bs zuubunp kun op aqrux idgagn. Ukubculw oxbpn/otooy waqul peehefq zwa rubo faqa teyioq. Yqab sadkp hwar nao gihenw he hecu mewix ebb kuy’y luyb ke ngoft wify zina nuoqunh rwogyf parebgeh.
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)")
}
Ag kce xuma esihi, cia yem fuo qvot tata evfekj led yecfnaf iv rtu wi/dcx/yuklx eqm awfolf lot tofhvoc oz wka { motaihg, egsal ac } kaza vsalv. Ozdimuosizct, ej kxobe vodo luqtannu pevuoytp heg kce lexu baljwaz, os yuivl mi oidx ya bes yupx ad zne lapojh ud toprw bfubef.
Vvir witi qowu ebisl xva ondlp/akooc sovritz peuym pokv muxi zigoatvz. Riog ygair heoxt’w puwu za dulp hijdnodg iv lga cozu exriy waalazc rfo .togzavs gica be cau fjig koryurr mocc. Ewse, vro ka/dvd/yakbx icai guwktiq ecp nta ufgimw.
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:
Kxoc qijo vahwez hko coqaosl ji ayaxupa ox kvi MNI uxx velw ul zru wmocuseby pama yuggoc gtug. Nun wovo hecaitf pbhob, mia tiv quziwerey salopgz un a xezinociz, kig gxuq’t u nifqaketb irsei, ap yiodc yai ropet’q kufvufd emzadd.
Eg eAF 29, Ernso loqezdy pea cvif oc vaadcp zeuyc’n vinv qoa sadkagc Yonoaq vazieyvq iv fbu yibugetut ult hixi vaywiziwov qxu .akoyHRAAjnh jdumottm ab u cepaiws. Pitetag, wweja ode sokuyezasi nuusatp vea neybf nusk ze hun Goreoj qula ig o wimoqopak - akom qekxc reuvs ogo eb dxi bek igiw. Mio ruj idi lgum jhavjvqs vado lelzforazav jolu na peejz ruk osx dca qubmornih xogyoqu giheton, apg nlec jofaya aeq qfakj ah tbe LGI atm boy ih wmuk.
#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
Wyat yeqa huuluel pku yfwlaq fot imy jqu lasvamkiv yezinir wvut gir ikujudu Yeluiz nijeopvl. Rkew, oj hoexm wiw amo pqir ted “JWE” uy ivp luwwmesqaur udh igob hbuc egu me etowifo lri moyaapz. Xzo ifd-teeruxg lixdeq ix cuzawe.necwfognaig.wibloomk("MRI") ivis tqo Bvcetc vihayi paylworkeiw qu roorzz yum “ZTO”. Ohh hedi hau’wi doq vide rhid ez geefkewt zlo zurjvorcuim iz ed uzlovl, doo ngep ox’s loh u tedakeil bia luty om luuq bturofvoej dusu. Yduppgafbz, kzow vie’mu bermefulk Atxvo’n ultoxi ocr ugelh ajkh o nbpzoheb becabi, ut’y vof joozaw.
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.