Vision Framework

Sep 18 2024 · Swift 5.10, 6.0, iOS 17.5, 18b4, Xcode 15.4, 16b6

Lesson 04: Unveiling New Vision Framework Features in iOS 18

Demo

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Here in Xcode 16, you can see the demo project. If you want to follow along, this is the same code as in the Starter folder in the materials for this lesson.

let supportedDevices = try! textDetectionRequest
  .supportedComputeStageDevices
if let mainStage = supportedDevices[.main] {
  if let cpuDevice = mainStage.first(where: { device in
    device.description.contains("CPU")
    }) {
      textDetectionRequest.setComputeDevice(cpuDevice, for: .main)
  }
}
let textDetectionRequest = VNRecognizeTextRequest()
guard let results = textDetectionRequest.results else {
  self.textRectangles = []
  return
}
self.textRectangles = results.compactMap { observation in
  guard let topCandidate = observation.topCandidates(1).first
    else { return nil }
  return (observation.boundingBox, topCandidate.string)
}
Task {
  await viewModel.detectText()
  viewModel.calculateMaxTextHeight()
}
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction 02 Next: Conclusion