Learn Courses My Dashboard

Scanning and Saving documents

I have 2 questions about some document type and how to work with it.
How to allow to an app to scan and save a documents via swift?
Also what is the type of the scanned document in swift(for example, the type of the image document is UIImage)?

hmm usually you just use the camera to take a picture (“scan”) then use that image (which can be opened using UIImage but from a file path), from there you can probably use that image to show in your app or do whatever you want with it

you might need permissions to access documents, camera, and gallery though

no, I use the code below:

import UIKit
import VisionKit

class ViewController: UIViewController {

override func viewDidLoad() {

@IBAction func neuFoto(_ sender: Any) {

// override func viewDidLayoutSubviews() {//Muss ich dass verwenden?
// super.viewDidLayoutSubviews()
// }
private func configureDocumentView() {
let scanningDocumentVC = VNDocumentCameraViewController()
scanningDocumentVC.delegate = self
self.present(scanningDocumentVC, animated: true, completion: nil)

extension ViewController:VNDocumentCameraViewControllerDelegate {//wanted to add UITableViewDelegate

func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
    for pageNumber in 0..<scan.pageCount {
        let image = scan.imageOfPage(at: pageNumber)
    controller.dismiss(animated: true, completion: nil)

And I want to know, how to configure some variable to save the photo taken in my app via user defaults?

You shouldn’t be saving photos to UserDefaults, that’s not a good practice

Then what do I need to use to save photos in my app?
What is the type of the variable that keeps photo that I need to save?
And is it enough easy as using user defaults?

It depends, are you only saving one photo? Or many?
What’s the purpose of the photo?

I need to save many photos using the code that placed upper or just simultaneously using this code because it’s very simple and short code. Now I have only this code on one ViewController, added Privacy - Camera Usage Description in Info.plist, and added one navigation controller and all trivial that I cannot write here.
After a user took one photo by default I need to save it.
And I need to save such way many photos as in built in photos app in any iPhone.
The purpose is to make something like a scanner but it’s not for working with this, only I want to make some simple app for fun. And after I make many updates it has to become something like a good scanner or something needed for people.

Then you just need to save it on the gallery like a normal photo… Then just access the photo from the gallery itself by making the user select it… Or maybe save the “path” of the photo from the gallery so you can access it easily using your app like a collectionview or something

I need to save a photo in my app but not in photos(built in any iPhone). How to do this?

You can save it as data to CoreData

But from your description I would NOT save it to UserDefaults

not sure if thats an option unless its just “data” as mikaela said… you can instead look for other solutions like maybe cloud storage (firebase) so you have your photo elsewhere and not on the phone

Is it easy to study core data?
Which way would be the easiest to study this?

“Easy” is relative, to the person. I would say it isn’t terribly difficult to pick up the basics

Here’s a great starting point

Is it enough to know info from this video to save photos in the app?
If not, what will be enough?

That video series teaches you about CoreData.

To actually save images you can google “how to save images to core data” but the videos above give you the background information that will really help you understand CoreData better than just copying/pasting code from a tutorial

Do you know how to save a photo in a ViewController, and then make it to display always it in another VC?

You should just write some code in one view controller that saves the photo and in a different view controller you write the code for displaying it

It will “always” display in whichever VC you write the code to display it

I asked because I use the Core Data to save images and I don’t understand which variable-types to use, i.e. UIImage, Binary Data(for images) etc?

You used core data to save the image as data I’m guessing. From that you must convert the data back to a UIImage, and then use a UIImageView to display it (or if using SwiftUI, I think just an Image object

How to convert the data back to a UIImage?
And if it’s not obvious how to do, how to use then UIImageView to display it?
I need some videos or books, or links.